cancel
Showing results for 
Search instead for 
Did you mean: 

Workflow script to copy document in same folder and continue workflow with new document

marcollirite
Confirmed Champ
Confirmed Champ

Hi all

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

1 ACCEPTED ANSWER

marcollirite
Confirmed Champ
Confirmed Champ

I have found a solution to this. First we copy the document using the .parent property of bpm_package and assign it to a new variable. Then we can remove the original document from bpm_package and add the new one in it's place, as with the following code:

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

View answer in original post

3 REPLIES 3

gdharley
Elite Collaborator
Elite Collaborator

Are you using activiti or alfresco ECM?
This looks more like an ECM workflow question.

Thanks,
greg

Hi Greg

This is for a workflow within Alfresco (using the activiti engine). I may have got confused about the two categories, but I thought ECM would be mainly for content modelling/structuring and BPM would be for everything workflow related?

marcollirite
Confirmed Champ
Confirmed Champ

I have found a solution to this. First we copy the document using the .parent property of bpm_package and assign it to a new variable. Then we can remove the original document from bpm_package and add the new one in it's place, as with the following code:

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