0

For one of my workflows, I want to be able to select a document in my start task. Then, I would like to execute a script to make a copy of this document in the same folder, and continue the workflow with the new document (if this is possible). I don't have much java experience but I'm trying to achieve something along the lines of:

<script>
      var path = bpm_package.children[0].displayPath;
      var newdoc = bpm_package.children[0].copy(path);
      newdoc.save();
      bpm_package = newdoc;
</script>

Any help would be greatly appreciated!

Marcus

2 Answers2

2

Basically the argument in copy function is the object of parent node and not a path to parent node.

So the below code will do the work.

bpm_package.children[0].copy(bpm_package.children[0].parent);

You do not need to call save or any other function after that.Basically this are javascript api of alfresco. You can take a look on below link for more details.

http://docs.alfresco.com/4.1/references/API-JS-Scripting-API.html

Krutik Jayswal
  • 3,165
  • 1
  • 15
  • 38
0

Thanks to Krutik for answering the first part of the answer. I'm adding the solution to changing the document in the workflow. This is done by adding and removing documents from the bpm_package property. The whole script is as below:

var newdoc = bpm_package.children[0].copy(bpm_package.children[0].parent);
bpm_package.removeNode(bpm_package.children[0]);
bpm_package.addNode(newdoc);