Skip to main content

Task allocation using expressions

Expressions in allocation rules are usually needed when you need to evaluate complex conditions and select some user that complies with conditions given in said expression.

To use expressions select the User property User id and the Expression option.

The expression created should return an array of ids, of the users that comply with the condition needed. Those user ids will be allocated.

Example

In an Onboarding process, a requester enters the information of a new position including job description, salary, etc.

The next activities that include setting requirements and gathering documents can be performed by any user whose Boss is the process requester.

Thus, we need to use an expression to find all users who share the requester as a Boss.

Assume in the first activity you save the Requester id in an attribute: <Onboarding.Requester>

  1. In the Performers definition, fifth step of the Process Wizard, click the activity to define.

  2. Select User Id as the property for the allocation and select Expression as condition. Click Select Expression

TaskAllocation18

  1. Tick the option Based on the result of an expression.

TaskAllocation40

  1. Select the New option.

TaskAllocation41

  1. Create the following expression

TaskAllocation42

// Create an array
var Users = new ArrayList();

// Create the filter for the requester
var parameters = new FilterParameters();
parameters.AddParameter("@Requester", <Onboarding.Requester.Id>);

// Get all users whose boss is the requester
var SearchUsers = Me.getXPath("entity-list('WFUser', 'idBossUser=@Requester')", parameters);

// Count how many users comply
var HowManyUsers = SearchUsers.size();

if (HowManyUsers > 0)
{
// Add each user to the array
for (var i = 0; i < HowManyUsers; i++)
{
var idUser = SearchUsers[i].getXPath("Id");
Users.Add(idUser);
}
}

Users;

Give the expression a name.

It should look like this.

TaskAllocation42