cancel
Showing results for 
Search instead for 
Did you mean: 

Change Task Owner Based On Task Owner Before

jakepens71
Champ in-the-making
Champ in-the-making
Hello,

I am running Alfresco 4.0.2 Enterprise.

I would I have three Tasks which are A, B, and C.

All three tasks are assigned to a pooled group. When the workflow gets to task B a member of that group claims the task. (Through the claim button on the workflow page.) Then after that user who claims the task rejects the workflow back to A which then will get sent back to B after A does what needs done.

Now, I would like the user who claimed task B BEFORE being sent to task A to be the owner of the task again AFTER it gets sent back to Task B.

I have tried doing something like this:

I wanted to create a process variable for it so I do this at the start. Is that right?

  var orderMatOwner = null;


then in my user task:


   <sequenceFlow id="flow3" name="Traveller Resubmitted" sourceRef="submitCPMTraveller" targetRef="orderMaterial"></sequenceFlow>
    <userTask id="orderMaterial" name="Order Materials" activiti:candidateGroups="GROUP_WF_CPMCustomerService" activiti:formKey="cpmwf:CPMOrdermaterial">
      <extensionElements>
        <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>
                   <![CDATA[
                    if (typeof orderMatOwner != null) bpm_assignee = orderMatOwner) (also have tried task.owner, task.Owner, and task.getOwner)
                    execution.setVariable('cpmwf_previousComment', bpm_comment);
                    execution.setVariable('cpmwf_wfName', bpm_workflowDescription);
                    execution.setVariable('bpm_comment', bpm_comment);
                    if (typeof bpm_workflowDueDate != 'undefined') task.dueDate = bpm_workflowDueDate;
                    if (typeof bpm_workflowPriority != 'undefined') task.priority = bpm_workflowPriority;
                    ]]>
                    </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[
                    execution.setVariable('orderMatOwner', bpm_assignee) (also have tried task.owner, task.Owner, and task.getOwner)
                    execution.setVariable('wf_reviewOutcome', task.getVariable('cpmwf_CPMorderMaterialOutcome'));
                    execution.setVariable('bpm_comment', task.getVariable('bpm_comment'));]]></activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>
    </userTask>

Is this possible and if so can someone point me in the right direction please?

Thanks!
1 REPLY 1

jakepens71
Champ in-the-making
Champ in-the-making
I got this to work by doing the following:

Created process variable from model (EngineringOwner is the new variable i created):


<type name="putwf:baseWF">
         <parent>wf:activitiReviewTask</parent>
         <properties>
            <property name="putwf:previousComment">
               <title>Placeholder to display comment from previous task at Task Level</title>
               <type>d:text</type>
            </property>
            <property name="putwf:wfName">
               <title>Placeholder to display comment from previous task at Task Level</title>
               <type>d:text</type>
            </property>
            <property name="putwf:EngineerOwner">
               <title>Placeholder to display the assignee(claimer) of the Order Material Task</title>
               <type>d:text</type>
            </property>
         </properties>
        <overrides>
            <property name="bpm:packageActionGroup">
                <default>add_package_item_actions</default>
            </property>
            <property name="bpm:packageItemActionGroup">
                <default>edit_and_remove_package_item_actions</default>
            </property>
        </overrides>
      </type>


Assigned that to the form to store the variable:


<config evaluator="task-type" condition="putwf:EngineeringRedraw2">
      <forms>
         <form>
            <field-visibility>
               <show id="putwf:wfName" />
               <show id="putwf:previousComment" />
               <show id="taskOwner" />
               <show id="putwf:EngineerOwner" />
               <show id="bpm:priority" />
               <show id="bpm:dueDate" />
               <show id="bpm:status" />
               <show id="packageItems" />
               <show id="bpm:comment" />
               <show id="putwf:engineeringOutcome2" />
            </field-visibility>
            <appearance>
               <set id="" appearance="title" label-id="workflow.set.task.info" />
               <set id="info" appearance="" template="/org/alfresco/components/form/3-column-set.ftl" />
               <set id="progress" appearance="title" label-id="workflow.set.task.progress" />
               <set id="items" appearance="title" label-id="workflow.set.items" />
               <set id="response" appearance="title" label-id="workflow.set.response" />

               <field id="putwf:wfName" label-id="name.workflow.field.message" description-id="name.workflow.field.message">
                  <control template="/org/alfresco/components/form/controls/info.ftl" />
               </field>
               <field id="putwf:previousComment" label-id="name.workflow.field.prevcomment">
                  <control template="/org/alfresco/components/form/controls/info.ftl" />
               </field>
               <field id="taskOwner" set="info" />
               <field id="putwf:EngineerOwner" label-id="pennUnited.workflow.field.engineerowner">
                  <control template="/org/alfresco/components/form/controls/info.ftl" />
               </field>
               <field id="bpm:priority" set="info" read-only="true">
                  <control template="/org/alfresco/components/form/controls/workflow/ftkpriority.ftl" />
               </field>
               <field id="bpm:dueDate" set="info" label-id="workflow.field.due">
                  <control template="/org/alfresco/components/form/controls/info.ftl" />
               </field>
               <field id="bpm:status" set="progress" />
               <field id="packageItems" set="items" />
               <field id="bpm:comment" label-id="workflow.field.comment" set="response">
                  <control template="/org/alfresco/components/form/controls/textarea.ftl">
                     <control-param name="style">width: 95%</control-param>
                  </control>
               </field>
               <field id="putwf:engineeringOutcome2" label-id="workflow.field.outcome" set="response">
                  <control template="/org/alfresco/components/form/controls/workflow/activiti-transitions.ftl" />
               </field>
            </appearance>
         </form>
      </forms>
   </config>


Then in workflow xml i did:


     
                   <userTask id="EngineeringRedraw" name="Redraw Engineering Part" activiti:candidateGroups="GROUP_WF_Engineering" activiti:formKey="putwf:EngineeringRedraw">
      <extensionElements>
        <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string><![CDATA[
                  
                  if (typeof putwf_EngineerOwner != 'undefined')
                    {
                       task.setAssignee(putwf_EngineerOwner);
                    }
                    else
                    {
                       task.setAssignee(null);
                   
                    }
           
                    execution.setVariable('putwf_previousComment', bpm_comment);
                    execution.setVariable('putwf_wfName', bpm_workflowDescription);
                    execution.setVariable('bpm_comment', bpm_comment);
                    if (typeof bpm_workflowDueDate != 'undefined')  task.dueDate = bpm_workflowDueDate;
                    if (typeof bpm_workflowPriority != 'undefined') task.priority = bpm_workflowPriority;]]></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 children = bpm_package.getChildren();
                    var localengTaskRes = null;
                    for( var i=0; i<children.length; i++)
                    {
                        var thisNode = children;
                        var engResult = thisNode.properties['putwf:engResult'];
                        if ( engResult != null && engResult.length != 0 )
                        {
                             localengTaskRes = thisNode.properties['putwf:engResult'];
                        }
                        thisNode.properties['putwf:engResult'] = null;                  
                        thisNode.save();                                      
                    }

                    if( localengTaskRes == "Automatically Completed" )
                    {
                        task.setVariableLocal('putwf_engineeringOutcome', "Engineering Finished");
                        task.setVariableLocal('bpm_comment', "Engineering drawing has been uploaded.");
                        execution.setVariable('wf_reviewOutcome', "Engineering Finished");
                        //execution.setVariable('bpm_comment', "Engineering drawing has been uploaded.");
                    }
                    else
                    {
                        putwf_EngineerOwner = task.getAssignee();
                        execution.setVariable('wf_reviewOutcome', task.getVariable('putwf_engineeringOutcome'));
                        execution.setVariable('bpm_comment', task.getVariable('bpm_comment'));
                         execution.setVariable('putwf_EngineerOwner', task.getAssignee());
                    }]]></activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>
    </userTask>