<< Click to Display Table of Contents >> Access the i-th record of a collection |
In some situations it is necessary to obtain or manipulate information of a specific record in a collection.
To do this you do not need to iterate over the whole collection and stop when you find the desired record. By knowing the position of the record in the collection you can easily access it through an expression.
The syntax used to access this information is as follow:
•To obtain information
Collection.get(index of the record). getXPath("Attribute")
•To set
Collection.get(index of the record). setXPath("Attribute",value)
Take into account that indexes of the records within the collection always start from 0. |
Suppose a company uses Bizagi to raffle different prizes among its clients. An external service generates a random number which represents the position of the client within the collection of clients. As the number of clients can be very large, the name of the winner is stored in a string type attribute. Once obtained this information, the client is checked as winner in the data base in order to exclude him/her for future raffles.
The following is the data model associated to the process:
To obtain the information of the winner from the clients collection, follow the next steps:
1. Go to the activity where the raffle is performed and create an on enter expression. Then create an expression module.
2. The random number generated by the external service is stored in the WinnerIndex attribute. Type the following expression to obtain the name of the winner from the clients collection. It will be stored in the WinnerName attribute.
//Obtain the index of the winner within the clients collection
WinnerIndex=<Raffle.WinnerIndex>;
//Obtain the clients collection
Clients=Me.getXPath("Raffle.Clients");
//Obtain the name of the winner by using the clients index within the clients collection
<Raffle.WinnerName>=Clients.get(WinnerIndex).getXPath("Name");
You can also obtain the id of the record currently being iterated.
//Obtain the name of the winner by using the id
<Raffle.WinnerName>=Clients.get(WinnerIndex).getXPath("Id");
//Obtain the name of the winner by using the surrogate key
<Raffle.WinnerName>=Clients.get(WinnerIndex).getXPath("idClients");
The surrogate key is built concatenating "id", with the Entity's name (e.g. idClients) |
3. Now to identify the client as a winner use the following sentence. This will set the Winner attribute to true.
//Update the information of the winner by using the clients index within the clients collection
Clients.get(WinnerIndex).setXPath("Winner",true);
4. Go to the Work Portal to test the expression.
In order to have a better performance, when manipulating data inside a cycle, before entering the cycle extract in a variable the Process entity and then use the variable inside the cycle.
Example:
var max = 1500; ... |
Last Updated 1/6/2022 4:15:31 PM