Retrieving the ID of an Assignee Completing a Task in Workflows

In a workflow, it is common to have more than one user interact with different tasks in a particular state. As a task progresses through the workflow, it is then helpful to know which user last interacted with the task. To help with this, there is an automated process that can be set to retrieve the ID of the last assignee to a task. This way, should there be an error with the task and it needs to be sent back to the previous state, it can also be determined on who the last user was while in that state.

There are two script options that can be used according to user preference. Both are placed on a State Editor on the 'On Exit' tab. Both scripts can also be combined with a condition to guarantee the user ID is returned, if desired.

Using Manager Interface to Return the User ID in a Workflow

In the script below, the ID of the user who performs the transition is obtained via the Manager interface ("step" is a shorthand for getting the Manager). This script retrieves the ID of an assignee and stores it in a workflow variable which is being represented by "WorkflowVariable" in this case.

var assigneeId = step.getCurrentUser().getID();
node.getWorkflowInstance(workflow).setSimpleVariable("WorkflowVariable", assigneeId);

For the example below, the workflow variable is called 'MyVariable'.

To implement this, open the desired workflow, right-click on the desired state and select Edit state > On Exit > Add new Business Action > edit Operation > Execute JavaScript. Add any necessary binds for the workflow.

One aspect to be aware of is that a user with the 'STEP Workflow Administrator' privilege potentially could have completed the task while the workflow was assigned to a group, resulting in the group ID being returned instead. Use the condition mentioned at the end of this topic if returning the user ID only for the workflow variable is a concern.

Using Task Interface to Return the User ID in a Workflow

Alternately, the ID of the Assignee can also be obtained via the Task interface. This too is implemented by opening up the desired workflow, right-clicking on the desired state, and selecting Edit state > On Exit > Add new Business Action > edit Operation > Execute JavaScript. Again, replace "WorkflowVariable" with the variable for the workflow, and add any necessary binds for the workflow.

var instance = node.getWorkflowInstance(workflow);
var assigneeId = instance.getTaskByID("MyState").getAssignee().getID();
instance.setSimpleVariable("WorkflowVariable", assigneeId);

Again, an aspect to be aware of is that a user with the 'STEP Workflow Administrator' privilege potentially could have completed the task while the workflow was assigned to a group. This could result in the ID of a user group being stored in the Workflow Variable, versus the individual user ID.

For this reason, adding a condition on the transitions out of the state in conjunction with the script on the Task interface will guarantee that the ID stored in the variable will be an individual user and not the group ID.

Condition to Aid in returning User ID in Workflows

Below is the condition that can be added to the Transitions Editor on the 'On Transition tab' out of the state that is retrieving the user ID. This condition in conjunction with the script, will make it impossible for a task to exit the state if the assignee is a group ID. To implement the condition, right-click on the transition > Edit Transition > Condition > Add new Business Condition > True if value for Attribute"" "null" > Execute JavaScript. Add any binds needed for the workflow.

var instance = node.getWorkflowInstance(workflow);
if(instance.getTaskByID("MyState").getAssignee() instanceof com.stibo.core.domain.Group) {
	condition = false;
	resultMessage = "Claim the Task before submitting.";
else {
	condition = true;
} 

If a user wishes to send a task back to a previous state and re-assign it to the user who worked on the task in that state, refer to the Assigning Tasks Using Business Rules topic.