Activiti : use custom process variable in JS

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

Activiti : use custom process variable in JS

Hi,

I try to use a process variable in a script of my workflow. Here's what I did :

Model :

<type name="mywf:startTask">

  <parent>wf:submitAdhocTask</parent>
     <properties>
        <property name="mywf:newFoldersParent">
          <type>d:noderef</type>
          <mandatory>true</mandatory>
       </property>
   </properties>
</type>

Workflow :

<startEvent id="start" name="Start" activiti:formKey="mywf:startTask"></startEvent>
<userTask id="myTask" name="Saisie Matricule" activiti:assignee="${bpm_assignee.properties.userName}" activiti:formKey="mywf:userTask">
  <extensionElements>
    <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
      <activiti:field name="script">
      <activiti:string><![CDATA[var file = bpm_package.children[0];

var newFoldersParentRef = mywf_newFoldersParent;
var dest = search.newFoldersParentRef);
var folder = dest.createFolder('New folder');
file.move(folder);
}]]></activiti:string>
      </activiti:field>
    </activiti:taskListener>
  </extensionElements>
</userTask>

Script:

var workflow = actions.create("start-workflow");
workflow.parameters.workflowName = "activiti$mywf";
workflow.parameters["bpm:workflowDescription"] = "My workflow";
workflow.parameters["bpm:workflowPackage"] = document;
workflow.parameters["bpm:assignee"] = people.getPerson(document.properties['cm:creator']);
var futureDate = new Date();
futureDate.setDate(futureDate.getDate() + 3);
workflow.parameters["bpm:workflowDueDate"] = futureDate;
workflow.parameters["mywf:newFoldersParent"] = companyhome.childByNamePath("Sites/mysite/documentLibrary/new_folders").nodeRef;
workflow.execute(document);

What's the correct way to access the variable mywf:newFoldersParent in the script ? I tried execution.getVariable('mywf:newFoldersParent'), execution.getVariable('mywf_newFoldersParent') : none of them work. I looked in the workflow console (desc path activiti$1234) => the property is set correctly with the script.

I use Alfresco 5.2.f with the SDK (3.1.0).

Thanks in advance

1 Reply
Highlighted
Established Member

Re: Activiti : use custom process variable in JS

You can use execution.getVariable() and task.getVariable() to get value of workflow variables in script.

In your scrit you can use like below: 

var newFoldersParentRef = execution.getVariable("mywf_newFoldersParent");

Regards,

Vidhi

ContCentric

Regards,
Vidhi | ContCentric