How can I update task properties with data captured from the start task ?

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

How can I update task properties with data captured from the start task ?

I am trying to update task properties with data captured from the START task in the same workflow

 <startEvent id="startevent1" name="Start" activiti:formKey="scwf:submitReviewTask">
    <extensionElements>
            <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
                  <activiti:field name="script">
                    <activiti:string>
                        <![CDATA[
                            execution.setVariable('scwf_toto', task.getVariable('scwf_numAgent'));
                        ]]>
                    </activiti:string>
                  </activiti:field>
            </activiti:taskListener>
        </extensionElements>
    </startEvent>
    <endEvent id="endevent1" name="End"></endEvent>
    <userTask id="usertask1" name="Budget" activiti:candidateGroups="GROUP_Budget" activiti:formKey="scwf:activitiBudgetReview">
      <extensionElements>
        <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
              <activiti:field name="script">
                <activiti:string><![CDATA[
                    task.setVariable('scwf_historique', scwf_toto);                    
                ]]></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[
                    if(task.getVariableLocal('scwf_approveRejectOutcome') == 'Approve') {
                        var newApprovedCount = scwf_approveCount + 1;
                        execution.setVariable('scwf_approveCount', newApprovedCount);
                    }
                ]]>
            </activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>
    </userTask>

When I try to run the workflow, I get an error message.

scwf_numAgent is a property from an aspect.

scwf_historique is a custom property that I add to my activitiBudgetReview modele

Any help please

Thanks in advance.

1 Reply
livier
Active Member II

Re: How can I update task properties with data captured from the start task ?

It works on the other tasks but it doesn't when I try to get the data from the start task

    <userTask id="usertask1" name="Budget" activiti:candidateGroups="GROUP_Budget" activiti:formKey="scwf:activitiBudgetReview">
      <extensionElements>
        <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>
                <![CDATA[
                    if(task.getVariableLocal('scwf_approveRejectOutcome') == 'Approve') {
                        var newApprovedCount = scwf_approveCount + 1;
                        execution.setVariable('scwf_approveCount', newApprovedCount);
                    }
                    execution.setVariable('scwf_tmp', task.getVariableLocal('bpm_comment'));
                ]]>
            </activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>
    </userTask>

<userTask id="usertask5" name="RH" activiti:candidateGroups="GROUP_RH" activiti:formKey="scwf:activitiRHReview">
      <extensionElements>
        <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>
                <![CDATA[
                    task.setVariable('scwf_historique', scwf_tmp);

                ]]>
            </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[
                    if(task.getVariableLocal('scwf_approveRejectOutcome') == 'Approve') {
                        var newApprovedCount = scwf_approveCount + 1;
                        execution.setVariable('scwf_approveCount', newApprovedCount);
                    }
                    
                ]]>
            </activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>
    </userTask>