Multi instance

cancel
Showing results for 
Search instead for 
Did you mean: 
debananda
Member II

Multi instance

Hi Folks

I have a scenario, where I have to create a user task, and it has to be approved by 4 users, say A,B,C,D . How to create the flow. I don't want to create separate 4 user task and then make it parallel. What I want is to create a single user ask , which has to be approved by 4 different users and then it shall move forward. 

If i use multi instance what i need to pass in loop carnality, collection, element variable etc . Please find the screenshot for requirement. 

1 Reply
abhinavmishra14
Advanced

Re: Multi instance

You can choose to use activiti:candidateGroups. Create a group and all 4 users to the group. When the task starts it goes to the pool. This particular process uses a "pooled assignment". Every user can claim the task and approve it. Once the approval is completed from all 4 users you can mark the task as fully completed.

Example:

<serviceTask id="submitDocServiceTask1" name="Submit Document"
          activiti:class="org.alfresco.repo.workflow.activiti.script.AlfrescoScriptDelegate">

          <extensionElements>
               <activiti:field name="script">
                    <activiti:string><![CDATA[execution.setVariable('cmsWorkflow_approveCount', 0);]]></activiti:string>
               </activiti:field>
          </extensionElements>
     </serviceTask>


<userTask id="salesReviewUsertask1" name="My Team Review"
          activiti:candidateGroups="GROUP_My_Team" activiti:formKey="cmsWorkflow:activitiSalesReview">

          <extensionElements>
               <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
                    <activiti:field name="script">
                         <activiti:string>
                              <![CDATA[
                                   if(task.getVariableLocal('cmsWorkflow_approveRejectOutcome') == 'Approve') {
                              var finalApprovalCount = cmsWorkflow_approveCount + 1;
                              execution.setVariable('cmsWorkflow_approveCount', finalApprovalCount);
                              }
                         ]]>

                         </activiti:string>
                    </activiti:field>
               </activiti:taskListener>
          </extensionElements>
    </userTask>

Keep incrementing the count until it reaches 4. Then on the sequenceFlow, write a condition expression which will validate the count before proceeding to next step.

example:

<sequenceFlow id="decisionOnReviewFlow" sourceRef="exclusivegateway1" targetRef="approvedNotificationUsertask">
   <conditionExpression xsi:type="tFormalExpression"><![CDATA[${cmsWorkflow_approveCount == 4}]]></conditionExpression>
</sequenceFlow>

If number of users are not defined and a group can have more than 4 users, then use a generic logic. Where get the number of users from the candidate group and use the expression accordingly instead of hardcoded value as 4. 

~Abhinav
(ACSCE, AWS SAA, Azure Admin)