title: Alfresco Adding Two Step Approval Workflow
body: <p>I have modified current lifecycle workflow according to the form fields I need but that workflow is only good for one step of approval. So if i start the workflow and assign it to somebody, he/she would just approve/reject it and that comes back to me.</p>
  
  <p>What I need is if first approver approves the workflow, it should go to the second approver and if approved/rejected should go back to the Initiator (me in this case)</p>
  
  <p>My acitiviti definition file is</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  
  &lt;definitions id="reimbur-definitions"
               typeLanguage="http://www.w3.org/2001/XMLSchema"
               expressionLanguage="http://www.w3.org/1999/XPath"
               targetNamespace="http://activiti.org/bpmn20" 
               xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:activiti="http://activiti.org/bpmn"&gt;
  
      &lt;process id="activitireimburApproval" name="Reimbursement Application Process"&gt;
          &lt;extensionElements&gt;
               &lt;!-- When process is deleted/cancelled, status should be set to draft --&gt;
               &lt;activiti:executionListener event="end" class="org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener"&gt;
                  &lt;activiti:field name="script"&gt;
                       &lt;activiti:string&gt;
                          if(cancelled || deleted) {
                              for (var i = 0; i &amp;lt; bpm_package.children.length; i++)
                              {
                                 if (!bpm_package.children[i].hasAspect("rei:status"))
                                 {
                                      bpm_package.children[i].properties["rei:status"] = "Draft";
                                      bpm_package.children[i].save();
                                 }
                              }
                          }
                       &lt;/activiti:string&gt;
                    &lt;/activiti:field&gt;
              &lt;/activiti:executionListener&gt;
           &lt;/extensionElements&gt;
          &lt;startEvent id="start"
              activiti:formKey="rei:reimbursubmitReviewTask" name="Submit Application" /&gt;
  
          &lt;sequenceFlow id='flow1' 
              sourceRef='start'
              targetRef='reviewTask'&gt;
               &lt;extensionElements&gt;
                   &lt;activiti:executionListener event="take" class="org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener"&gt;
                      &lt;activiti:field name="script"&gt;
                           &lt;activiti:string&gt;
                              for (var i = 0; i &amp;lt; bpm_package.children.length; i++)
                              {
                                 if (!bpm_package.children[i].hasAspect("rei:status"))
                                 {
                                    bpm_package.children[i].addAspect("rei:status");
                                 }
                              }
                           &lt;/activiti:string&gt;
                        &lt;/activiti:field&gt;
                  &lt;/activiti:executionListener&gt;
               &lt;/extensionElements&gt;
          &lt;/sequenceFlow&gt;
  
          &lt;userTask id="reviewTask" name="Review Reimbursement Application"
              activiti:formKey="rei:reimburactivitiReviewTask"&gt;
             &lt;extensionElements&gt;
                 &lt;activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener"&gt;
                    &lt;activiti:field name="script"&gt;
                       &lt;activiti:string&gt;
  
                           for (var i = 0; i &amp;lt; bpm_package.children.length; i++)
                           {
                              if (bpm_package.children[0].hasAspect("rei:status")) {
                                  bpm_package.children[i].properties["rei:status"] = "In Review";
                                  bpm_package.children[i].save();
                              }
                           }
                       &lt;/activiti:string&gt;
                    &lt;/activiti:field&gt;
                 &lt;/activiti:taskListener&gt;
                 &lt;activiti:taskListener event="assignment" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener"&gt;
                    &lt;activiti:field name="script"&gt;
                       &lt;activiti:string&gt;
                          execution.setVariable('wf_reviewOutcome', task.getVariable('wf_reviewOutcome'));
                       &lt;/activiti:string&gt;
                    &lt;/activiti:field&gt;
                 &lt;/activiti:taskListener&gt;
             &lt;/extensionElements&gt;
             &lt;humanPerformer&gt;
                  &lt;resourceAssignmentExpression&gt;
                      &lt;formalExpression&gt;${bpm_assignee.properties.userName}&lt;/formalExpression&gt;
                  &lt;/resourceAssignmentExpression&gt;
              &lt;/humanPerformer&gt;
          &lt;/userTask&gt;
  
          &lt;sequenceFlow id='flow2' 
          sourceRef='reviewTask'
              targetRef='reviewDecision' /&gt;
  
           &lt;userTask id="reviewTask2" name="Review Reimbursement Application"
              activiti:formKey="rei:reimburactivitiReviewTask"&gt;
             &lt;extensionElements&gt;
                 &lt;activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener"&gt;
                    &lt;activiti:field name="script"&gt;
                       &lt;activiti:string&gt;
  
                           for (var i = 0; i &amp;lt; bpm_package.children.length; i++)
                           {
                              if (bpm_package.children[0].hasAspect("rei:status")) {
                                  bpm_package.children[i].properties["rei:status"] = "In Review";
                                  bpm_package.children[i].save();
                              }
                           }
                       &lt;/activiti:string&gt;
                    &lt;/activiti:field&gt;
                 &lt;/activiti:taskListener&gt;
                 &lt;activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener"&gt;
                    &lt;activiti:field name="script"&gt;
                       &lt;activiti:string&gt;
                          execution.setVariable('wf_reviewOutcome', task.getVariable('wf_reviewOutcome'));
                       &lt;/activiti:string&gt;
                    &lt;/activiti:field&gt;
                 &lt;/activiti:taskListener&gt;
             &lt;/extensionElements&gt;
             &lt;humanPerformer&gt;
                  &lt;resourceAssignmentExpression&gt;
                      &lt;formalExpression&gt;${bpm_assignee.properties.userName}&lt;/formalExpression&gt;
                  &lt;/resourceAssignmentExpression&gt;
              &lt;/humanPerformer&gt; 
          &lt;/userTask&gt;   
  
          &lt;sequenceFlow id='flow3' 
          sourceRef='reviewTask2'
              targetRef='reviewDecision' /&gt;
          &lt;exclusiveGateway  id="reviewDecision" name="Review Reimbursement Application" /&gt; 
  
          &lt;sequenceFlow id='flow4' sourceRef='reviewDecision' targetRef='approved' &gt;
              &lt;conditionExpression xsi:type="tFormalExpression"&gt;${wf_reviewOutcome == 'Approve'}&lt;/conditionExpression&gt;
          &lt;/sequenceFlow&gt;
  
          &lt;sequenceFlow id='flow5' 
          sourceRef='reviewDecision'
              targetRef='rejected' /&gt;
  
         &lt;userTask id="approved" name="Reimbursement Approved"
              activiti:formKey="wf:approvedTask" &gt;
              &lt;documentation&gt;
                  The document was reviewed and approved.
              &lt;/documentation&gt;
              &lt;extensionElements&gt;
                 &lt;activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener"&gt;
                    &lt;activiti:field name="script"&gt;
                       &lt;activiti:string&gt;
  
                          for (var i = 0; i &amp;lt; bpm_package.children.length; i++)
                          {
                             if (bpm_package.children[0].hasAspect("rei:status")) {
                                 bpm_package.children[i].properties["rei:status"] = "Approved";
                                 bpm_package.children[i].save();
                             }
                          }
                       &lt;/activiti:string&gt;
                    &lt;/activiti:field&gt;
                 &lt;/activiti:taskListener&gt;
              &lt;/extensionElements&gt;
              &lt;humanPerformer&gt;
                  &lt;resourceAssignmentExpression&gt;
                      &lt;formalExpression&gt;${initiator.properties.userName}&lt;/formalExpression&gt;
                  &lt;/resourceAssignmentExpression&gt;
              &lt;/humanPerformer&gt;
          &lt;/userTask&gt;
  
          &lt;userTask id="rejected" name="Reimbursement Rejected"
              activiti:formKey="wf:rejectedTask" &gt;
              &lt;documentation&gt;
                  The reimbursement was reviewed and rejected.
              &lt;/documentation&gt;
              &lt;extensionElements&gt;
                 &lt;activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener"&gt;
                    &lt;activiti:field name="script"&gt;
                       &lt;activiti:string&gt;
  
                          for (var i = 0; i &amp;lt; bpm_package.children.length; i++)
                          {
                             if (bpm_package.children[0].hasAspect("rei:status"))
                             {
                                bpm_package.children[i].properties["rei:status"] = "Draft";
                                bpm_package.children[i].save();
                             }
                          }
                       &lt;/activiti:string&gt;
                    &lt;/activiti:field&gt;
                 &lt;/activiti:taskListener&gt;
              &lt;/extensionElements&gt;
              &lt;humanPerformer&gt;
                  &lt;resourceAssignmentExpression&gt;
                      &lt;formalExpression&gt;${initiator.properties.userName}&lt;/formalExpression&gt;
                  &lt;/resourceAssignmentExpression&gt;
              &lt;/humanPerformer&gt;
          &lt;/userTask&gt;
  
          &lt;sequenceFlow id='flow6' sourceRef='approved'
              targetRef='end' /&gt;
  
          &lt;sequenceFlow id='flow7' sourceRef='rejected'
              targetRef='end' /&gt;
  
          &lt;endEvent id="end" /&gt;
  
  
  
      &lt;/process&gt;
  
  &lt;/definitions&gt;
  </code></pre>
  
  <p>My model file is </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;model name="rei:workflowreimburmodel" xmlns="http://www.alfresco.org/model/dictionary/1.0"&gt;
  
      &lt;!-- Optional meta-data about the model --&gt;
      &lt;description&gt;Workflow reimbur Model&lt;/description&gt;
      &lt;author&gt;&lt;/author&gt;
      &lt;version&gt;1.0&lt;/version&gt;
  
     &lt;imports&gt;
          &lt;import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d" /&gt;
          &lt;import uri="http://www.alfresco.org/model/content/1.0" prefix="cm" /&gt;
          &lt;import uri="http://www.alfresco.org/model/bpm/1.0" prefix="bpm" /&gt;
          &lt;import uri="http://www.alfresco.org/model/user/1.0" prefix="usr" /&gt;
          &lt;import uri="http://www.alfresco.org/model/workflow/1.0" prefix="wf" /&gt;
      &lt;/imports&gt;
  
      &lt;namespaces&gt;
          &lt;namespace uri="rei.model" prefix="rei" /&gt;
      &lt;/namespaces&gt;
  
      &lt;constraints&gt;
          &lt;constraint name="rei:status" type="LIST"&gt;
              &lt;parameter name="allowedValues"&gt;
                  &lt;list&gt;
                      &lt;value&gt;Draft&lt;/value&gt;
                      &lt;value&gt;In Review&lt;/value&gt;
                      &lt;value&gt;Approved&lt;/value&gt;
                  &lt;/list&gt;
              &lt;/parameter&gt;
          &lt;/constraint&gt;
      &lt;/constraints&gt;   
  
       &lt;types&gt;
          &lt;type name="rei:reimbursubmitReviewTask"&gt;
              &lt;title&gt;Submit Reimbursement Application&lt;/title&gt;
              &lt;parent&gt;wf:submitReviewTask&lt;/parent&gt;
               &lt;mandatory-aspects&gt;
                 &lt;aspect&gt;rei:myAspect&lt;/aspect&gt;
              &lt;/mandatory-aspects&gt;
           &lt;/type&gt;
           &lt;type name="rei:reimburactivitiReviewTask"&gt;
              &lt;parent&gt;wf:activitiReviewTask&lt;/parent&gt;
               &lt;mandatory-aspects&gt;
                 &lt;aspect&gt;rei:myAspect&lt;/aspect&gt;
              &lt;/mandatory-aspects&gt;
           &lt;/type&gt;
      &lt;/types&gt;
  
      &lt;aspects&gt;
          &lt;!-- Status property is used to manage workflow approval --&gt;
          &lt;aspect name="rei:status"&gt;
              &lt;title&gt;Status&lt;/title&gt;
              &lt;properties&gt;
                  &lt;property name="rei:status"&gt;
                      &lt;title&gt;Status&lt;/title&gt;
                      &lt;type&gt;d:text&lt;/type&gt;
                      &lt;default&gt;Draft&lt;/default&gt;
                      &lt;constraints&gt;
                          &lt;constraint ref="rei:status" /&gt;
                      &lt;/constraints&gt;
                  &lt;/property&gt;
              &lt;/properties&gt;
          &lt;/aspect&gt;
          &lt;aspect name="rei:myAspect"&gt;
               &lt;title&gt;My Aspect&lt;/title&gt;
               &lt;properties&gt;               
                  &lt;property name="rei:workflowAmount"&gt;
                     &lt;type&gt;d:float&lt;/type&gt;
                     &lt;mandatory&gt;true&lt;/mandatory&gt;
                  &lt;/property&gt;                     
               &lt;/properties&gt;
          &lt;/aspect&gt;
  
      &lt;/aspects&gt;  
  
  
  
  &lt;/model&gt;
  </code></pre>
  
  <p>and my share-congif-form file is </p>
  
  <pre><code> &lt;config evaluator="string-compare" condition="activiti$activitireimburApproval"&gt;
        &lt;forms&gt;
           &lt;form&gt;
              &lt;field-visibility&gt;
                 &lt;show id="bpm:workflowDescription" /&gt;
                 &lt;show id="rei:workflowAmount" /&gt;
                 &lt;show id="bpm:assignee" /&gt;
                 &lt;show id="bpm:sendEMailNotifications" /&gt;
              &lt;/field-visibility&gt;
              &lt;appearance&gt;
                 &lt;set id="" appearance="title" label-id="workflow.set.general" /&gt;
                 &lt;set id="info" appearance="" template="/org/alfresco/components/form/3-column-set.ftl" /&gt;
                 &lt;set id="assignee" appearance="title" label-id="workflow.set.assignee" /&gt;
                 &lt;set id="other" appearance="title" label-id="workflow.set.other" /&gt;
  
                 &lt;field id="bpm:workflowDescription" label-id="Expenditure was for" mandatory="true"&gt;
                    &lt;control template="/org/alfresco/components/form/controls/textarea.ftl"&gt;
                       &lt;control-param name="style"&gt;width: 95%&lt;/control-param&gt;
                    &lt;/control&gt;
                 &lt;/field&gt;
                 &lt;field id="rei:workflowAmount" label-id="Amount ($)" set="info" mandatory="true"&gt;
                    &lt;control template="/org/alfresco/components/form/controls/textfield.ftl"&gt;
                 &lt;/control&gt;
                 &lt;/field&gt;
                &lt;field id="bpm:assignee" label-id="workflow.field.reviewer" set="assignee" /&gt;
                 &lt;field id="bpm:sendEMailNotifications" set="other" read-only="true"&gt;
                    &lt;control template="/org/alfresco/components/form/controls/workflow/email-notification.ftl" /&gt;
                 &lt;/field&gt;
              &lt;/appearance&gt;
           &lt;/form&gt;
        &lt;/forms&gt;
     &lt;/config&gt;
  
  
      &lt;config evaluator="task-type" condition="rei:reimbursubmitReviewTask"&gt;
        &lt;forms&gt;
           &lt;form id="workflow-details"&gt;
              &lt;field-visibility&gt;
                 &lt;show id="bpm:sendEMailNotifications" /&gt;
              &lt;/field-visibility&gt;
              &lt;appearance&gt;
                 &lt;set id="" appearance="title" label-id="workflow.set.workflow.more_info" /&gt;
              &lt;/appearance&gt;
           &lt;/form&gt;
  
           &lt;form&gt;
              &lt;field-visibility&gt;
                 &lt;show id="message" /&gt;
                 &lt;show id="taskOwner" /&gt;
                 &lt;show id="bpm:taskId" /&gt;
                 &lt;show id="bpm:status" /&gt;
                 &lt;show id="rei:workflowAmount" /&gt;
                 &lt;show id="bpm:assignee" /&gt;
                 &lt;show id="bpm:sendEMailNotifications" /&gt;
              &lt;/field-visibility&gt;
              &lt;appearance&gt;
                 &lt;set id="" appearance="title" label-id="workflow.set.task.info" /&gt;
                 &lt;set id="info" appearance="" template="/org/alfresco/components/form/3-column-set.ftl" /&gt;
                 &lt;set id="other" appearance="title" label-id="workflow.set.other" /&gt;
  
                 &lt;field id="message"&gt;
                    &lt;control template="/org/alfresco/components/form/controls/info.ftl" /&gt;
                 &lt;/field&gt;
                 &lt;field id="taskOwner" set="info" /&gt;
                 &lt;field id="bpm:taskId" set="info"&gt;
                    &lt;control template="/org/alfresco/components/form/controls/info.ftl" /&gt;
                 &lt;/field&gt;
                &lt;field id="rei:workflowAmount" set="info" label-id="Amount ($)"&gt;
                    &lt;control template="/org/alfresco/components/form/controls/info.ftl" /&gt;
                 &lt;/field&gt;
  
                 &lt;field id="bpm:assignee" label-id="workflow.field.assign_to" set="assignee" /&gt;
                 &lt;field id="bpm:status" set="progress" /&gt;
                 &lt;field id="bpm:sendEMailNotifications" set="other" /&gt;
              &lt;/appearance&gt;
           &lt;/form&gt;
        &lt;/forms&gt;
     &lt;/config&gt;  
  
     &lt;config evaluator="task-type" condition="rei:reimburactivitiReviewTask"&gt;
        &lt;forms&gt;
           &lt;form&gt;
              &lt;field-visibility&gt;
                 &lt;show id="message" /&gt;
                 &lt;show id="taskOwner" /&gt;
                 &lt;show id="bpm:assignee" /&gt;
                 &lt;show id="rei:workflowAmount" /&gt;
                 &lt;show id="bpm:taskId" /&gt;
                 &lt;show id="bpm:status" /&gt;
                 &lt;show id="bpm:comment" /&gt;
                 &lt;show id="wf:reviewOutcome" /&gt;
              &lt;/field-visibility&gt;
              &lt;appearance&gt;
                 &lt;set id="" appearance="title" label-id="workflow.set.task.info" /&gt;
                 &lt;set id="info" appearance="" template="/org/alfresco/components/form/3-column-set.ftl" /&gt;
                 &lt;set id="response" appearance="title" label-id="workflow.set.response" /&gt;
  
                 &lt;field id="message"&gt;
                    &lt;control template="/org/alfresco/components/form/controls/info.ftl" /&gt;
                 &lt;/field&gt;
                 &lt;field id="taskOwner" set="info" /&gt;
                 &lt;field id="bpm:taskId" set="info"&gt;
                    &lt;control template="/org/alfresco/components/form/controls/info.ftl" /&gt;
                 &lt;/field&gt;
                 &lt;field id="rei:workflowAmount" set="info" label-id="Amount ($)"&gt;
                    &lt;control template="/org/alfresco/components/form/controls/info.ftl" /&gt;
                 &lt;/field&gt;
                 &lt;field id="bpm:status" set="progress" /&gt;
                 &lt;field id="bpm:assignee" label-id="workflow.field.assign_to" set="assignee" /&gt;
                 &lt;field id="bpm:comment" label-id="workflow.field.comment" set="response"&gt;
                    &lt;control template="/org/alfresco/components/form/controls/textarea.ftl" /&gt;
                 &lt;/field&gt;
                 &lt;field id="wf:reviewOutcome" label-id="workflow.field.outcome" set="response"&gt;
                    &lt;control template="/org/alfresco/components/form/controls/workflow/activiti-transitions.ftl" /&gt;
                 &lt;/field&gt;
              &lt;/appearance&gt;
           &lt;/form&gt;
        &lt;/forms&gt;
     &lt;/config&gt;
  </code></pre>
  
  <p>In above files, I wanted to have the assignee field appearing in the first approver form, so that he/she can assign it to second approver. But I do not see that on the task/workflow description window and after the approval/rejection, the workflow does not go to the second approver instead comes back to the initiator.</p>
  
  <p>What am I doing wrong? Please guide me.</p>
  
  <p>Thanks in advance.</p>