10-21-2016 10:39 AM
I need to move an approved document from one folder to the initiator home page folder. I think that I can do it from the workflow's task, adding script to this:
<userTask id="valutaCSS" name="Valuta Certificato di Servizio (semplice)" activiti:formKey="psw:activitiValutaCS">
<extensionElements>
<activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
<activiti:field name="script">
<activiti:string><![CDATA[if(task.getVariableLocal('psw_esitoValutazioneCS') == 'Approvato'){
execution.setVariable('psw_prosegui', true);
}else{
execution.setVariable('psw_prosegui', false);
}]]></activiti:string>
</activiti:field>
</activiti:taskListener>
</extensionElements>
<humanPerformer>
<resourceAssignmentExpression>
<formalExpression>${bpm_assignee.properties.userName}</formalExpression>
</resourceAssignmentExpression>
</humanPerformer>
</userTask>
I tried to change this code for a simple test:
var dest = companyhome.childByNamePath("Repository/Simulazioni");
for (var i = 0; i < bpm_package.children.length; i++)
{
bpm_package.children[i].move(dest);
}but it doesn't get the dest variable
11-04-2016 10:55 AM
Ok, I solved this using your advices:
<extensionElements>
<activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
<activiti:field name="script">
<activiti:string><![CDATA[if(task.getVariableLocal('psw_esitoValutazioneCS') == 'Approvato'){
execution.setVariable('psw_prosegui', true);
var nomeUtente = initiator.properties["cm:userName"]; //initiator.properties.userNamel'utente/"+nomeUtente);
var dest = companyhome.childByNamePath("/Home page del
for (var i = 0; i< bpm_package.children.length; i++){
bpm_package.children[i].move(dest);
}
}else{
execution.setVariable('psw_prosegui', false);
}]]></activiti:string>
</activiti:field>
<activiti:field name="runAs">
<activiti:string>admin</activiti:string>
</activiti:field>
</activiti:taskListener>
</extensionElements>
Thanks everybody for the help!
10-21-2016 11:16 AM
I think that the destination reference is wrong, try the following:
var dest = companyhome.childByNamePath("/Simulazioni");
Hope this helps ![]()
10-22-2016 10:07 AM
Ok, thank you, now it works ![]()
I'm trying to change the path so that every time it moves the file to the initiator user homepage. If I try:
var dest = companyhome.childByNamePath("/Home page dell'utente/MPapini");
It works, but when I tried
var percorso = "/Home page dell'utente/" + ${initiator.properties.userName};
var dest = companyhome.childByNamePath(percorso);
Alfresco returns me this:
org.activiti.engine.ActivitiException: Exception while invoking TaskListener: Exception while invoking TaskListener: 09220009 Failed to execute supplied script: missing ; before statement (AlfrescoJS#3)
10-21-2016 03:11 PM
You can move folder this way two points to consider here.
10-21-2016 03:14 PM
Mittal Patoliya For the first point, another option is to use the runas to set a user like system to perform the move.
By doing so, there will be no permission restriction.
10-22-2016 10:21 AM
So, if I want to move from a private folder to another private folder I have to use runas?
I'm reading some previous post about it but it's hard to figure out how to use runas here.
10-22-2016 08:28 PM
10-22-2016 08:42 PM
Try to add following code to your process definition
<extensionElements>
<activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
<activiti:field name="script">
<activiti:string><![CDATA[if(task.getVariableLocal('psw_esitoValutazioneCS') == 'Approvato'){
execution.setVariable('psw_prosegui', true);
}else{
execution.setVariable('psw_prosegui', false);
}]]>
</activiti:string>
</activiti:field>
<activiti:field name="runAs">
<activiti:string>
admin
</activiti:string>
</activiti:field>
</activiti:taskListener>
</extensionElements>
11-04-2016 10:55 AM
Ok, I solved this using your advices:
<extensionElements>
<activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
<activiti:field name="script">
<activiti:string><![CDATA[if(task.getVariableLocal('psw_esitoValutazioneCS') == 'Approvato'){
execution.setVariable('psw_prosegui', true);
var nomeUtente = initiator.properties["cm:userName"]; //initiator.properties.userNamel'utente/"+nomeUtente);
var dest = companyhome.childByNamePath("/Home page del
for (var i = 0; i< bpm_package.children.length; i++){
bpm_package.children[i].move(dest);
}
}else{
execution.setVariable('psw_prosegui', false);
}]]></activiti:string>
</activiti:field>
<activiti:field name="runAs">
<activiti:string>admin</activiti:string>
</activiti:field>
</activiti:taskListener>
</extensionElements>
Thanks everybody for the help!
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.