Greetings to the community, I am using alfresco 6.0.0 Community Edition and I would like to move a document attached to a task to another node on the complete event of the task.
I found from here https://community.alfresco.com/thread/204737-workflow-parallel-group-review-with-move about this "move" function so what I am currently doing is the following:
/tasks/{taskId}/items (POST) method of the alfresco REST API.
The part of my bpmn where I move the file is below:
<activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
<activiti:field name="script">
<activiti:string>
java.lang.System.out.println(bpm_package.children.length);
for (var i = 0; i < bpm_package.children.length; i++){
bpm_package.children.move("b162be92-fb36-44f0-83c1-4432b8261c5a");
}
</activiti:string>
</activiti:field>
</activiti:taskListener>
Where b162be92-fb36-44f0-83c1-4432b8261c5a is the node id of a folder I have created.
Unfortunately, when i complete this task I get the following error:
Node Type: {http://www.alfresco.org/model/content/1.0}content, Node Aspects: [{http://www.alfresco.org/model/content/1.0}auditable, {http://www.alfresco.org/model/system/1.0}referenceable, {http://www.alfresco.org/model/system/1.0}localized] 0.0 2018-11-15 15:43:24,936 ERROR [impl.interceptor.CommandContext] [http-apr-8080-exec-3] Error while closing command context org.activiti.engine.ActivitiException: Exception while invoking TaskListener: Exception while invoking TaskListener: 10150807 Failed to execute supplied script: 10150806 TypeError: Cannot find function move in object Node Type: {http://www.alfresco.org/model/content/1.0}content, Node Aspects: [{http://www.alfresco.org/model/content/1.0}auditable, {http://www.alfresco.org/model/system/1.0}referenceable, {http://www.alfresco.org/model/system/1.0}localized]. (AlfrescoJS#10) at org.activiti.engine.impl.persistence.entity.TaskEntity.fireEvent(TaskEntity.java:742) at org.activiti.engine.impl.persistence.entity.TaskEntity.complete(TaskEntity.java:184) at org.activiti.engine.impl.cmd.CompleteTaskCmd.execute(CompleteTaskCmd.java:52) at org.activiti.engine.impl.cmd.CompleteTaskCmd.execute(CompleteTaskCmd.java:24) at org.activiti.engine.impl.cmd.NeedsActiveTaskCmd.execute(NeedsActiveTaskCmd.java:59) at org.activiti.engine.impl.interceptor.CommandInvoker.execute(CommandInvoker.java:24) at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:57) at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:47) at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:131) at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:45) at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:31) at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:40) at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:35) at org.activiti.engine.impl.TaskServiceImpl.complete(TaskServiceImpl.java:178) at org.alfresco.rest.workflow.api.impl.TasksImpl.update(TasksImpl.java:821) at sun.reflect.GeneratedMethodAccessor1556.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498)
Could anyone shed light on this please? Any help is greatly appreciated :)
Solved
The problem was that the move function expects a node element not the id I passed to it (String).
Fixed code below:
<activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
<activiti:field name="script">
<activiti:string>
for (var i = 0; i < bpm_package.children.length; i++){
var p = bpm_package;
var doc = p.children[i];
var myNode = initiatorhome.childByNamePath("foldertomove/testFolder"); <!-- the names of the nodes under the root directory where the file should be moved to-->
doc.move(myNode);
}
</activiti:string>
</activiti:field>
</activiti:taskListener>