Use EntityArray for batch actions

<< Click to Display Table of Contents >>

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

Use EntityArray for batch actions

When you want to handle multiple records in one Action, executing a single Expression, you can rely on batch actions. Expressions for batch 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 Stakeholder 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

 

Approvedstate = CHelper.getEntityAttrib("RequestState","idRequestState","idRequestState = 1","");

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