All product information in wiki.bizagi.com is only valid for Bizagi BPM Suite 9.1.X.
For newer Bizagi BPM Suite versions (10.X and up) please visit the User Guide.
 

How to use Iteration

From Business Process Management, BPM and Workflow Automation Wiki | BizAgi BPMS

Jump to: navigation, search

<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

Image:Business_Rules8_Image010.jpg
 

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

Image:Bulletazul.gif 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.


Image:Business_Rules8_Image011.jpg


Image:Bulletazul.gif To count the entries of a relationship that meets a condition


Image:Business_Rules8_Image012.jpg


Image:Bulletazul.gif 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.


Image:Business_Rules8_Image013.jpg

 

How to Modify Information on a relationship

Image:Bulletazul.gif 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.


Image:Business_Rules8_Image014.jpg


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.



Image:Bulletazul.gif To modify the entries of a relationship that meet a condition:


Image:Business_Rules8_Image015.jpg


Add the Value of an Attribute (Column) of a relationship by Rows

Image:Bulletazul.gif 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.


Image:Business_Rules8_Image016.jpg


Image:Bulletazul.gif Sum the entries that meet a condition.


Image:Business_Rules8_Image017.jpg


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

Image:Bulletazul.gif To delete the entries that meet a condition, use an expression in the Iterate Over Fact.

vble.Delete();


Image:Business_Rules8_Image018.jpg


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.


Image:Bulletazul.gif Add a blank entry to a relationship.


Declare the variable oEntEntityName

oEntEntityName = CEntityManager.GetEntity("EntityName");

oEntEntityName.Attributes["idEntityKey"].Value = <idOtherEntityKeyRelatedPV>;

oEntEntityName.Add();

Image:Business_Rules8_Image019.jpg


Image:Bulletazul.gif Add an entry in an entity with values in the attributes:


Image:Business_Rules8_Image020.jpg


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:


Image:Bulletazul.gif To save it in a variable:

id = oEntEntityName.Add(); where id is a variable that should be declared

Image:Bulletazul.gif To save it in an attribute:

<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 />