logo

Identifying the executor of a dynamic swimlane by the First Response mechanism in a script

Sometimes you may need to assign a swimlane executor during the execution of a business process. If there must be only one executor, you can use a dynamic swimlane, defined by a script. However, in some cases, you need a task in a swimlane to be received by a group of users with the First Response mechanism (the first user to start the execution of the task becomes the executor in the swimlane), and at the same time, the group is defined during the business process execution. For this, you can use a script executed upon changing the swimlane settings.

For example, assume there is a Request Processing process. Requests are received in the main office, and the processing takes place in branch offices. A branch office is selected when receiving a request. Then the task to process the request must be sent to the employees of the selected branch office so that one of them executed the task.

Process map:



Context variables:

  • Executor - User type.
  • User group - User Group type.
  • Job Position - Organizational Structure Item


The Branch Office swimlane must have the following settings:

  • Type - dynamic (selected from list);
  • Check the box Use the First Response mechanism;
  • Variable to define/store executor - the Executor context variable.



"Change Swimlane" script

After selecting a user group, the script to change the settings of the Branch Office swimlane is executed:

// get the settings of the swimlane, whose executor is stored in the Executor variable
var settings = (EntityUserSettings)context.GetSettingsFor(c => c.Executor);
 // reset the list of groups and job positions in the swimlane settings
settings.Workers.Clear();
// add an organizational structure item from the JobPosition context variable to the swimlane settings
settings.Workers.Add(new Worker { WorkerType = OrganizationItemDTO.MetadataUid, WorkerId = context.JobPosition.Id });
// add a user group from the UserGroup context variable to the swimlane settings
settings.Workers.Add(new Worker { WorkerType = UserGroupDTO.MetadataUid, WorkerId = context.UserGroup.Id });
// save the changed swimlane settings
settings.Save();

Add the following namespaces to the script:
using EleWise.ELMA.Security.Types.Settings;
using EleWise.ELMA.Security.DTO.Models;
using EleWise.ELMA.Security.Models;