Use EntityArray for Merged actions

<< Click to Display Table of Contents >>

Navigation:  Low-code Process Automation > Studio Cloud - Authoring environment > Bizagi Studio > Process wizard > Business Rules > Business Rules examples > Collections and entities >

Use EntityArray for Merged actions

When you want to handle multiple records in one Action, executing a single Expression, you can rely on Merged actions. Expressions for Merged actions have an special syntax to navigate through the records injected in the rule. All records are handled using the EntityArray object:

 

for (var i = 0 ; i < EntityArray.length ; i ++){

   EntityArray[i].setXPath("Attribute", value);

 EntityArray[i].getXPath("Attribute");

}

 

Example

Imagine you want to approve several vacation requests from your employees. The company has a policy for people who take their vacations on December: they will all participate in a raffle and win a trip.

You want to handle the vacation approval using an expression, and the winner of the prize will launch a process to deliver it.

 

What you need to do

1. Create the data model that will support the scenario

2. Create a Search that checks for all vacation requests of your direct employees.

3. Create a batch action to execute an expression that will: mark all records as approved, move forward in each process and launch the prize process

4. Enable the Vacations request process to continue after the batch approval.

5. Create a trigger to manage the prize.

 

Create the data model that will support the scenario

The Data model for this process is very simple. An entity called VacationRequest holds most the the data for the case, and it has a related entity relationship with the Request State parameter entity that holds the states of the request. The States entity is important in this case, because depending on them a supervisor will be able to find the pending requests.

 

EntityArray1

 

Create a Search that checks for all vacation requests of your direct employees

We have a Persona called Employee who has a search configured to find all pending vacation requests made by their subordinates.

This search form has two default values: one, the Boss as the current logged in user, and two the request state, to filter by the requests that are pending.

 

EntityArray2

 

Notice that the form has two fields that are read only. The Supervisor has a default value that is built using the expression shown in the image below.

 

EntityArray3

 

Create a batch action to execute an expression

The action that will mark all requests as approved after searching for them will look as follows. Remember to check the Group several items option in the Advanced wizard.

 

EntityArray4

 

EntityArray5

 

EntityArray6

 

var parameters = new FilterParameters();

parameters.AddParameter("@Code", "AP");

Approvedstate = CHelper.getEntityAttrib("RequestState","idRequestState","Code = @Code",parameters);

random = CHelper.Math.Rand(0,EntityArray.length);

CHelper.trace("Raffle","random "+random);

for (var i = 0 ; i < EntityArray.length ; i ++)

{

   EntityArray[i].setXPath("VacationLeaveState", Approvedstate);

 if (i == random)

 {

         EntityArray[i].setXPath("Rafflewin", true);

         CHelper.trace("Raffle","i raffle "+i);

 }

}

 

We will use a Conditional event to move all processes that have been approved, forward in the flow.

 

EntityArray7

 

Create a trigger to manage the prize

The trigger to launch the price winner will be as follows.

 

EntityArray8


Last Updated 10/7/2024 11:36:28 AM