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

cancel
Showing results for 
Search instead for 
Did you mean: 
marcollirite
Active Member II

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

Jump to solution

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 Solution

Accepted Solutions
marcollirite
Active Member II

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

Jump to solution

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 solution in original post

3 Replies
gdharley
Intermediate

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

Jump to solution

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

Thanks,
greg

marcollirite
Active Member II

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

Jump to solution

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
Active Member II

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

Jump to solution

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);