Iterate over XPath element

<< Click to Display Table of Contents >>

Navigation:  Bizagi Studio > Process wizard > Business Rules > Business rules elements >

Iterate over XPath element


Iterate over XPath allows you to carry out iterations (or cycles) over a collection XPath, that is, a one-to-many relationship.

You can access each record of the collection individually to carry out operations such as: modify values, retrieve values, or perform calculations and validations with values.

The collection you iterate can be filtered to only retrieve specific records.


What you need to do in Bizagi

1. Create a Scripting expression

2. Declare a variable to store the elements of the collection.

3. Include an Iterate over XPath element defining the collection XPath to be iterated, including filters if required.

4. Within the iteration cycle include an expression element to perform the calculations required.

5. Save the rule.



In the following scenario you work in the loan department of a bank. Two applicants respectively request analysis of their borrowing capability to ascertain they qualify for a loan. The bank performs a financial analysis and assesses the applicant's repayment capacity.

The Process entity for this process is Request.  Each request can have multiple Applicants; thus there is a one-to-many relationship between Request and Applicants. Additionally each applicant will have a Customer Snapshot, to keep a record of the applicant's financial capability at the time of the request.

A rule must evaluate each applicant based on preliminary information namely the base income and variable income of the application. The rule will calculate the total income from these figures.




1. Create a rule On Exit of the Activity where the data is entered.


2. Declare the following variables:

Applicant (object) to store the collection records.

MonthlyBaseIncome (int) to hold the base income value for future calculation

MonthlyVarIncome (int) to hold the variable income value for future calculation.

TotalIncome (int) to store the total of both incomes.




3. Include the Iterate over XPath element.

Select the Applicant variable declared earlier to store the collection records.

Select the XPath collection. In this case we select Request.Applicants.




4. Include an expression element to calculate the total income.




Enter the following code in the Edit Expression window:


MonthlyBaseIncome = Applicant.getXPath("CustomerSnapshot.MonthlyBaseIncome");
MonthlyVarIncome = Applicant.getXPath("CustomerSnapshot.MonthlyVariableIncome");
if (!BAIsBlank(MonthlyBaseIncome))
  TotalIncome = TotalIncome + MonthlyBaseIncome
if (!BAIsBlank(MonthlyVarIncome))
  TotalIncome = TotalIncome + MonthlyVarIncome
Applicant.setXPath("CustomerSnapshot.MonthlyTotalIncome", TotalIncome);


Note that the object variable, Applicant, is used to get and set values to each record individually.


Variable.getXPath("attribute within the collection");


Variable.setXPath("attribute within the collection", value to set);


If the XPath collection has been filtered, the iteration would only affect the records that comply with the filter.