How to use Iteration
From Business Process Management, BPM and Workflow Automation Wiki | BizAgi BPMS
<keywords content="keywords">iterate over fact, find value relationship, find information, count entries, modify information, update information, add values, delete entries, add entries</keywords>
Contents |
Use Iterate over Fact
Iterate over Fact can be used to carry out iterations or cycles over a one-to-many relationship EXCLUSIVELY when the relationship cannot be accessed directly through the data model using XPath.
This module allows you to access each of the entries in the one-to-many relationship (also known as a fact) to evaluate them, to carry out operations such as modifying the entries, deleting entries from the relationship, searching for information, counting entries, etc.
The most common example of this is accessing a collection included in Parameter entities. For example, the parameter entity Supplier has a collection of Products that it supplies. Then, if the user wants to iterate the Products of the Supplier, both being Parameter entities, the user has to user Iterate Over Fact.
Example
Using the image above, imagine that in a Purchase request process, some quotations must be requested to evaluate the best one, and then purchase with the best offer.
The process has a parameter entity with the company's Suppliers and an entity with all the Products that can be purchased. Each Supplier provides many Products, thus, there is a one-to-many relationship between Supplier and Product.
Some products have discounts. When the user enters the Quotation activity he/she must see the suppliers that are giving those discounts. To display the suppliers of the products with discounts, Iterate over Fact must be used: to go through all products and get the suppliers to be displayed in the work portal.
1. In the 4th step of the process wizard create an Expression On Enter.
This expression will iterate over the products and then add the suggested Suppliers to be displayed in the Work portal.
2. Build the expression.
The first thing is to declare all the variables that will be used in the expression.
The variable Products will be the one used in the Iterate Over Fact.
In order to Iterate over Product, we are going to need the KEY. This key is the identifier of each Supplier in the Products entity. Then, we have to first get the entity Supplier and get each one of its keys, to enter to the Iterate Over Fact.
Since Suppliers is not realted to the data model, it has to be used using CEntityManager.
Suppliers = CEntityManager.GetEntity("Supplier").GetEntityList("","","","");
Then, for each Supplier, we will get the Surrogate Key Value, which is the KEY we will use. Using the variable above we get the KEY:
SurrogateKey = Suppliers[Count].SurrogateKeyValue;
Having the KEY we can now use the Iterate Over Fact.
Then, we go one by one for each Product of the Supplier with the selected KEY.
To access the product's discount value we use: Products.Attributes["Discount"].Value
If the Product accessed has a disconunt, then we add it to an array.
(The array has to be previously declared SupplierArray as new ArrayList () )
Finally, having all the Suppliers in the array we go through the array using a For expression and adding one by one the Supplier to a collection: Quotation.SuggestedSuppliers with an Me.addRelation expression.
This is how the suggested Suppliers, look like in the Work Portal.
How to Find Information on a Relationship
To find entries on a relationship that meet a condition, you can use an if within the Iterate Over Fact containing one or more expressions such as:
VariableToIterate.Attributes[“Attribute”].Value Operator Value
For example, Products.Attributes["Approved"].Value == true
Value: Value used to compare the attribute from the grid. It can be the value of an attribute, a variable or a constant. The type of value should be taken into account.
Operator: The following can be used as operators:
Operator |
Name |
Example |
== |
Equal to Comparative |
VariableToIterate.Attributes[“Balance”].Value == 600 |
<> |
Other Than |
VariableToIterate.Attributes[“idClient”].Value <> <idClient> |
≥ |
Greater Than |
VariableToIterate.Attributes[“Balance”].Value > 600 |
≤ |
Less Than |
VariableToIterate.Attributes[“Balance”].Value < 600 |
>= |
Grater than or equal to |
VariableToIterate.Attributes[“Balance”].Value >= 600 |
<= |
Less than or equal to |
VariableToIterate.Attributes[“balance”].Value <= 60 |
How to Count the Entries of a relationship
To count the entries of a relationship, you can: Create an expression in the Iteration (Iterate Over Fact)
The expression can be created using a variable that will do the counting as follows:
Count = Count +1
Don’t forget to declare the Count variable at the beginning of the rule.
To count the entries of a relationship that meets a condition
You can also use an expression without using the Iterate Over Fact containing the following function:
Count = CEntityManager.GetEntity("EntityName",<idEntityName>).Facts["FactName"].ChildEntities.Count
EntityName: Name of the entity containing the relationship (Entity One).
idEntityName: Enter the foreign key that identifies each of the entries from the N entity with the related entity.
FactName: Name of the relationship.
How to Modify Information on a relationship
To modify the entries of a relationship, you can use an Expression containing the following in the Iterate Over Fact.
vble.Attributes[“Attribute1”].Value = value1;
vble.Attributes[“Attribute2”].Value = value2;
vble.Attributes[“AttributeN”].Value = valueN;
vble.Update();
vble: The name of the variable used for the Iterate Over Fact cycle.
Attribute1…n: Name of each of the attributes to be modified from the N entity.
Value1…n: Value that the entry will take on. It can be the value of an attribute, a variable or a constant. The type of value must be taken into account.
You can also use:
setAttrib("EntityName", vble.SurrogateKeyValue, “Attribute1”, value1);
setAttrib("EntityName", vble.SurrogateKeyValue, “Attribute2”, value2);
setAttrib("EntityName", vble.SurrogateKeyValue, “AttributeN”, valueN);
EntityName: Is the name of the N entity.
To modify the entries of a relationship that meet a condition:
Add the Value of an Attribute (Column) of a relationship by Rows
To sum all the existing entries of a relationship, use an Expression in the Iterate Over Fact.
sum= sum + vble.Attributes["Attribute"].Value;
Don’t forget to declare the add variable at the beginning of the rule.
Sum the entries that meet a condition.
You can store the value of the sum in an attribute by adding an expression at the end of the cycle:
<AttribName> = Sum;
vble: The name of the variable used for the Iterate Over Fact cycle.
Attribute: Name of the attribute of the N entity containing the value to be added.
AttribName: Attribute where you would like to save the total value of the sum.
Delete Entries of a relationship
To delete the entries that meet a condition, use an expression in the Iterate Over Fact.
vble.Delete();
vble: The name of the variable used for the Iterate Over Fact cycle.
Add Entries to a relationship
You cannot use the Iterate Over Fact module when a relationshipdoes not have any entries. Therefore, to add entries to a relationship, you can use the following expressions.
Add a blank entry to a relationship.
Declare the variable oEntEntityName
oEntEntityName = CEntityManager.GetEntity("EntityName");
oEntEntityName.Attributes["idEntityKey"].Value = <idOtherEntityKeyRelatedPV>;
oEntEntityName.Add();
Add an entry in an entity with values in the attributes:
Declare the variable oEntEntityName
oEntEntityName = CEntityManager.GetEntity("EntityName");
oEntEntityName.Attributes["idEntityKey"].Value = <idOtherEntityKeyRelatedPV>;
oEntEntityName.Attributes["Attribute1"].Value = value1;
oEntEntityName.Attributes["Attribute2"].Value = value2;
oEntEntityName.Attributes["AttributeN"].Value = valueN;
oEntEntityName.Add();
If you would like to save the entry id you have created, replace the last line with:
id = oEntEntityName.Add(); where id is a variable that should be declared
<AttributePath> = oEntEntityName.Add();
EntityName: Name of the N entity where you would like to add the entries
idEntityKey: Primary Key of the N entity where you would like to add the entries.
idOtherEntityKeyRelatedPV: Enter the path of the attribute that contains the value of the foreign key that identifies each of the entries of the N entity with the related entity.
Attribute1…n: Name of each of the attributes to be modified in the N entity.
Value1…n: Value that the entry will take on. It can be the value of an attribute, a variable or a constant. The type of value should be taken into account.
Note: It is very important to point out that EntityManager should only be used to get and work with entities that are not related to the case and that CANNOT be accessed directly by surfing the data model with XPath. This is because EntityManager does not get the data from the Scope, but from the Database directly. Thus the information that has not be persisted yet is not going to be found by the EntityManager. |
Related Information
<comments />