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
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
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.