Iterating using expressions

<< Click to Display Table of Contents >>

Navigation:  Bizagi Studio > Process wizard > Business Rules > Business Rules examples > Collections and entities >

Iterating using expressions

Overview

In scripting expressions, you can iterate elements such as collections or parameter entities using different functions. This article explains the syntax that you have to use to iterate different elements in Bizagi.  All functions that you can use to iterate elements in Bizagi can return three types of objects: BizagiArrayList, ArraysList, and Array. This section describes the syntax to iterate each type.

 

Bizagi Array Lists

A Bizagi Array List is a type of object similar to a collection, that contains all the information of the iterated object. The following functions return Bizagi Array Lists:

 

GetValuesAsCollection

Me.getXPath("entity-list('','')", parameters)

Me.getXPath("CollectionXpath")

<CollectionXpath>

 

If you declare a variable as an object type you can obtain the i-th row of the array list and the value of a particular column of that row as follows:

1.Declare an object that contains the whole table as a BizagiArrayList.

2.Declare an object to obtain the i-th row (this is optional)

3.Obtain the value of the i-th row in a specific column.

 

Here is an example using the entity-list function:

 

//Declare a variable that contains an array list with the whole table

var parameters = new FilterParameters();

parameters.AddParameter("@Parameter", <Entity.Parameter>);

var BizagiArrayListObject = Me.getXPath("entity-list('EntityName','Filter')",parameters);

//Iterate

for (var i = 0; i < BizagiArrayListObject.size(); i++){

 //Get the object that contains the row

 var RowObject = BizagiArrayListObject.get(i);

 //Get the value of a column of that row

 var Value = RowObject.getXPath("Attribute");

}

The following graphic shows what you can obtain from each object in the previous example:

 

Iterations1

 

What do you have to change is how do you define the BizagiArrayList object with the different functions. Iteration remains the same syntax.

 

Considerations

Entity-list cannot be used in User Jobs or Start Events

There is a consideration with the entity-list function. This function is contained by the Me object; however, the Me object is related to a work item, which means that a case and a BPMN element must be instantiated.

When you use expressions on exit Start Events, or in User Jobs, there is no work item associated because a case has not been created. Hence, no function from the Me object can be used.

If you need to iterate an entity in any of those scenarios, you have to use the function GetEntitylist.

 

var Entity = CEntityManager.GetEntity("EntityName").GetEntityList("","Filter","","");

for(var Counter=0; Counter< Entity.length;Counter++)

{

      //Get the attribute value of the record

        var Value= Entity[Counter].Attributes["AttributeOfTheEntity"].Value;

}

 

Array Lists

Some other functions return arrays lists. The way the are iterated is different from Bizagi Array Lists. Now you have to index the i-th record using square brackets [ ] after the name of the object that contains the array. Here are some examples of functions that return Array Lists:

 

Me.Assignees

CHelper.getUsersForPosition

CHelper.getAssignedWorkItems

CHelper.getSubProcessesId

 

Here is an example using the Me.Assignee function:

var ArrayObject= Me.Assignees;

for (var i = 0; i < ArrayObject.Count; i++){

 //Get the object that contains the row

 ArrayObjectRow = ArrayObject[i];

 //Get the value of a column of that row (e.g. Boss Id)

 ArrayObjectValue = ArrayObject[i].BossId;

}

The following graphic shows what you can obtain from each object in the previous example:

 

Iterations2

 

Arrays

Finally there are few functions that return an Array type object. Like in other programming languages, arrays are iterated differently because Arrays are considered as static data, meaning that the size is fixed. The following functions return Array:

 

CEntityManager.GetEntityListWithParameters

CEntityManager.GetEntity

 

 

Here there is an example of a function that returns an array:

 

var ArrayObject = CEntityManager.GetEntity("EntityName").GetEntityListWithParameters("",FilterParameters);

for(var Counter=0; Counter< ArrayObject.length; Counter++)

{

      //Get the attribute value of the record

        var Value= ArrayObject[Counter].Attributes["Attribute"].Value;

}

 

The following graphic shows what you can obtain from each object in the previous example:

 

Iterations3

 

The following table sums up how you can iterate the different element using expressions in Bizagi:

 

Object type

Iteration

How do you get the length

Examples

Bizagi Array List

Object.get(i).getXPath("Attribute")

Object.size()

GetValuesAsCollection

Me.getXPath(“entity-list(‘’,’’)",parameters)

Me.getXPath(“CollectionXpath”)

<CollectionXpath>

Array List

Object[i].Attribute

Object.Count

Me.Assignees

CHelper.getUsersForPosition

CHelper.getAssignedWorkItems

Array

Object[i].Attributes["Attribute"].Value

Object.length

CEntityManager.GetEntityListWithParameters

CEntityManager.GetEntity