cancel
Showing results for 
Search instead for 
Did you mean: 

Task variables and outcomes

drisschelouati
Champ on-the-rise
Champ on-the-rise
Hello activiti people,

i dont know if this was already answered, but i searched the forum and didnt find a thread on this. The only thing is that iam really new to programming stuff (i began coding in february 2015) but iam improving quick. I mainly use the embedded activiti engine in Alfresco, because  my job is about managing records and documents. Since i find that activiti is really an outstanding product, i really want to boost my learning curve.

As iam also new to JavaScript, i it is still difficult to manage task outcomes like in a mutliple review tasks process. I posted the following thread on Alfresco forums (https://forums.alfresco.com/forum/developer-discussions/workflow/property-error-javascript-variables...) with my process definition and the errors i get :


org.activiti.engine.ActivitiException: Exception while invoking TaskListener: Exception while invoking TaskListener: 09200041 Failed to execute supplied script: 09200040 ReferenceError: "adwf_approveCount" n'est pas défini (AlfrescoJS#2)


and


org.activiti.engine.ActivitiException: Unknown property used in expression: ${adwf_approveCount < 2})



There is also a screenshot of the process diagram to help understand my process, wich is based on a Jeff Potts tutorial. To summarize, i would like to learn efficiently how to declare, use and reuse this kind of approbation count variables in my processes to route documents towards the correct user or group of users.
iam kinda lost and would gladly welcome some help! Thank you!
2 REPLIES 2

drisschelouati
Champ on-the-rise
Champ on-the-rise
Hey everybody,

i found a solution to this problem. Apparently, there was a change of JavaScript engine used in activiti (engine embedded in Alfresco) from Rhino to Nashorn and that may have caused the issue i described above. Jeff Potts commited a few days ago to modify the script task and make it a service task using <code>org.alfresco.repo.workflow.activiti.script.AlfrescoScriptDelegate</code> Java class.

Instead of the old variable declaration, wich doesn't work anymore:

<code>
<scriptTask id="scripttask1" name="Submit" scriptFormat="javascript" activiti:autoStoreVariables="true">
      <script>execution.setVariable('scwf_approveCount', 0); execution.setVariable('scwf_tpApproved', false);</script>
</scriptTask>
</code>

Here is the new way to write it using a service task:

<code>
<serviceTask id="scripttask1" name="Submit" activiti:class="org.alfresco.repo.workflow.activiti.script.AlfrescoScriptDelegate">
      <extensionElements>
        <activiti:field name="runAs">
          <activiti:string><![CDATA[admin]]></activiti:string>
        </activiti:field>
        <activiti:field name="script">
          <activiti:string><![CDATA[
              execution.setVariable('scwf_approveCount', 0);
              execution.setVariable('scwf_tpApproved', false);
          ]]></activiti:string>
        </activiti:field>
      </extensionElements>
    </serviceTask>
</code>

I have tested the changes, and now it works.

vasile_dirla
Star Contributor
Star Contributor
Hi,
nice, I'm happy you solved it and thank you for sharing your challenges and solutions with the community.