Search code examples
alfrescoalfresco-shareactiviti

Is there a way to determine if the task was reassigned?


I have the multi-instance parallel workflow.

By using the Activiti ScriptTaskListener I write to the some aspect of the workflow-model.xml some details of the business process. For example, in the event start I write all assignees:

...
var assigneesNodeRefs = '';
for(var i = 0; i < bpm_assignees.size(); i++) {
    var assignee = bpm_assignees.get(i);
    assigneesNodeRefs += ' separator ' + assignee.nodeRef;
}
execution.setVariable('mswf_participants', assigneesNodeRefs);
...

In the event complete I write some another details:

...
var reviewDate = new Date();
var bpmComment = task.getVariable('bpm_comment');
var result;
if(task.getVariableLocal('mswf_reviewOutcome') == 'Approve') {
    result = 'Approve';
}
...

Etc.

Then, by using the Alfresco Content Services REST API (tasks) I can get the list of variables for my task in JSON format. Next, by using JavaScript, I can parse it and display various data tables in different places.

I'm interested in the ability to reassign assignees.

Let's say, if assignee_1 reassigns his task to assignee_2, I want to write this fact In the Activiti ScriptTaskListener.

Is it possible?


Solution

  • Yes you can do it by using assignment event

    example:

    <userTask id="test" name="Assignb" activiti:assignee="userName" activiti:formKey="<<formKey>>">
         <extensionElements>
    
          <activiti:taskListener event="assignment" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
        <activiti:field name="script">
         <activiti:string><![CDATA[
    
           var currAssignee = task.assignee;
              //gives current task assignee
           logger.log(currAssignee );
         ]]></activiti:string>
        </activiti:field>
       </activiti:taskListener>
          <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
    
           <activiti:field name="script">
         <activiti:string><![CDATA[
    
          var currAssignee = task.assignee;
    
                      ]]></activiti:string>
                   </activiti:field>
                </activiti:taskListener>
             </extensionElements>
     </userTask>