Include or replace the work allocation

<< Click to Display Table of Contents >>

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

Include or replace the work allocation

The functions assignWorkItem and assignWorkItem​ById are advanced functions that allow including or replacing assignees in any EXISTING User task, including intermediate events.

 

The syntax of assignWorkItem function is:

 

Me.Case.assignWorkItem(string sTaskName, int iNewUserId, bool bReplace)

 

And the syntax of assignWorkItemById function is:

 

Me.Case.assignWorkItemById(int iWorkItemId, int iNewUserId, bool bReplace)

 

The main parameters of these functions are:

The sTaskName: the unique name of the task to which the new user will be added or replaced in assignment.

The iWorkItemId: the identification number of the workItem of the task in which the new user will be added or replaced.

The iNewUserId: the identification number of the user to be added or replaced.

The bReplace: a Boolean attribute that determines whether the current allocation will be replaced or updated. If the value is true, it will replace all assigned users. If it is false, the user will be added to the assigned users.

 

note_pin

It is a good practice to save the allocated users in a table (collection) if the event is recurring (if after clicking next it is re-created). Then, the allocation rule will be to take the users from the collection.

 

Example

The following example will illustrate how to use these functions.

 

In a Personal Loan Request process, a new performer for the Decline Request event is added depending on the process phase. The assignation has the following rules:

 

Phase

Performer(s) of event

Applicants Prefilter

Case creator

Register Request Information

Case creator, Case creator's Boss

Verify Information

Case creator, Case creator's Boss, Security Leader.

Analysis Result

Security Leader.

Delivery

Loans Vice-president.

 

Before you continue

You have to define the task where the business rule where the users are added will be executed. In our example, we will set the execution of the expression On Enter the first activity of the new phase or On Exit of the last activity of the phase.

In our example, the activities selected will be:

 

On Enter of Verify Applicants Information Task. First Activity of Register Request Information phase.

On Enter of Verify Documentation and Information Sub-process. First Activity of Verify Information phase.

On Exit of Exception Request? gateway. Last Activity of Verify Information phase.

On Exit of Verify Collaterals and Products Task. Last Activity of Analysis Result phase.

 

Get the Task id of the Decline Request event from the database. In our example Decline Request's id is 552.

 

Procedure

1. Set the performer for the event using the step 5 of the process wizard.

 

2. Go to the first activity where the allocation will be modified and create an expression either On Exit or On Enter (previously defined). In our example, the first activity is Verify Applicants Information and the expression will be executed On Enter.

 

ReplaceAllocation_01

 

3. Add the following code to your expression in order to update the allocation.

 

// Get the Display name of the current activity
var actDisplayName = Me.Task.DisplayName;
// Load in a variable the Event id
var eventName = Me.Task.Name;
// For both positions vice-president and leader, we assume

// that there is only one user for each one

var oUser = CHelper.getUsersForPosition("LoansVicepresident");

var loansVpId = oUser[0];

oUser = CHelper.getUsersForPosition("SecurityLeader");

var secLeader = oUser[0];

// Compare the display name with the activities where the

// allocation will change
if (actDisplayName == "Verify Applicants Information")
{
  Me.Case.assignWorkItem(eventName, Me.Case.Creator.BossId, false);
}
else if (actDisplayName == "Verify Documentation and Information")
{
  Me.Case.assignWorkItem(eventName, secLeader, false);
}
else if (actDisplayName == "Exception Request?")
{
     // The allocation will be replaced
  Me.Case.assignWorkItem(eventName, secLeader, true);
}
else if (actDisplayName == "Verify Collaterals and Products")
{
  Me.Case.assignWorkItem(eventName, loansVpId, true);
}

 

ReplaceAllocation_02

 

If you prefer to use assignWorkItem​ById function, the code will be:

 

// Get the Display name of the current activity
var actDisplayName = Me.Task.DisplayName;
// Load in a variable the workitem id

var workItem = Me.Id;
// For both positions vice-president and leader, we assume

// that there is only one user for each one

var oUser = CHelper.getUsersForPosition("LoansVicepresident");

var loansVpId = oUser[0];

oUser = CHelper.getUsersForPosition("SecurityLeader");

var secLeader = oUser[0];
// Compare the display name with the activities where the
// allocation will change
if (actDisplayName == "Verify Applicants Information")
{
  Me.Case.assignWorkItem​ById(workItem, Me.Case.Creator.BossId, false);
}
else if (actDisplayName == "Verify Documentation and Information")
{
  Me.Case.assignWorkItem​ById(workItem, secLeader, false);
}
else if (actDisplayName == "Exception Request?")
{
     // The allocation will be replaced
  Me.Case.assignWorkItem​ById(workItem, secLeader, true);
}
else if (actDisplayName == "Verify Collaterals and Products")
{
  Me.Case.assignWorkItem​ById(workItem, loansVpId, true);
}

 

Save the expression and continue.

 

4. Add the expression created above in the corresponding event of the other activities previously defined. Once you have set the expression in all the activities, save your process and run it for testing.