Assigning Tasks Using Business Rules

While the assignee always will be set using the option selected on the State Editor's Assignee tab when entering a state, it is sometimes necessary to overwrite the assignee using a business action configured to run in the State Editor on the On Entry tab.

Overwriting the Assignee in Workflows with JavaScript

If the user has the ID of an assignee in a workflow variable, it is of course recommended that the user use the 'Fetch from Variable' option described in the Workflow State Editor Assignee Tab Option section of the Workflows documentation here. If, however, the user wishes to do it with a script On Entry, it can be done with the following script, given "WorkflowVariableHoldingID" holds the ID of a STEP User:

var instance = node.getWorkflowInstance(workflow);
var userObj = step.getUserHome().getUserById(instance.getSimpleVariable("WorkflowVariableHoldingID"));
instance.getTaskByID("MyState").reassign(userObj);

A user should have STEP Workflow Administrator privilege to use this 'reassign()' API method, however only if the 'Use executing user's write privilege' option on the Workflow Object editor is selected.

Reassigning to Previous Users in a Workflow

If a task is rejected back to a previous state, and needs to be worked on by the same user who initially worked on it in that particular state, this business rule can be used in combination with On Exit actions to return the correct assignee.

In the example below, a user picks up a task in the Edit sate, completes the assignment and submits it to the Review state. An On Exit business action is in place on the Edit state to store the data of who last worked on the task in a workflow variable. For more about On Exit scripts refer to Retrieving the ID of an Assignee Completing a Task in a Workflow in the Workflows documentation here.

Once in the Review state, a different user looks at the task and does not think it is ready to move forward. They sends it back to the Edit state to be re-evaluated by the user who originally submitted it.

To do this On Entry action of overriding the workflow default assignee back to the user who originally worked on it in the Edit state, the following script with the corresponding binds need to be put in place:

For the script below, for "MyState", the user should populate this with the ID of the state the script is being put on. Additionally, "WorkflowVariable" should be populated with the necessary workflow variable for the user's particular workflow.

var task = node.getWorkflowInstance(workflow).getTaskByID("MyState");
var reassignUser = node.getWorkflowInstance(workflow).getSimpleVariable("WorkflowVariable");
if(reassignUser!=null) {
    var user = manager.getUserHome().getUserById(reassignUser);
    if(user!=null){
        manager.executeWritePrivileged(function() {
            task.reassign(user);
        } );
    }
}