cancel
Showing results for 
Search instead for 
Did you mean: 

Activiti workflow - move a document

tssupremacy
Champ in-the-making
Champ in-the-making
Hi all,

I've made a workflow with review/approve transition steps. This workflow is called via JS, which is run via a rule:


function newBatch(assignee, doc){
  var workflowPackage = workflow.createPackage();
  workflowPackage.addNode(doc);
 
  var workflowDef = workflow.getDefinitionByName("activiti$StartReviewBatch");
  var parameters = new Object();
 
  parameters["bpm:assignee"] = assignee;
  parameters["bpm:workflowDescription"] = "Please review " + doc.name; 
 
  var workflowPath = workflowDef.startWorkflow(workflowPackage, parameters);
}

What I would like to do is have the workflow move the document attached to the appropriate Approved or Rejected folders. Here is a snippet of my current definition:

   <userTask id="usertask1" name="Review" activiti:assignee="${bpm_assignee.properties.userName}" activiti:formKey="wf:activitiReviewTask">
      <extensionElements>
        <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>execution.setVariable('wf_reviewOutcome', task.getVariable('wf_reviewOutcome'));</activiti:string>
          </activiti:field>
        </activiti:taskListener>
        <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string>if (task.getVariable('wf_reviewOutcome') == 'Approve'){
var dest= companyhome.childByNamePath("Sites/jstest/documentLibrary/Approved");
bpm_package.children[0].move(dest);
} else if (task.getVariable('wf_reviewOutcome') == 'Reject') {
var dest= companyhome.childByNamePath("Sites/jstest/documentLibrary/Rejected");
bpm_package.children[0].move(dest);</activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>
    </userTask>
    <endEvent id="endevent1" name="End"></endEvent>

I'm unsure if the bpm_package.children[0] is the correct way to reference the attached document. Gives a 'Failure' error box when clicking transition buttons.
Can anyone point me in the right direction? I've read the API and searched for hours on this.

Cheers
2 REPLIES 2

mitpatoliya
Star Collaborator
Star Collaborator
This is the way to refer it in the JBPM not sure about activii also you need to post the logs.
Which gives more details about the problem.

chalford
Champ in-the-making
Champ in-the-making
A stack trace or error log of some kind would be helpful here.

The code you posted seems correct, so the only two things I could suggest would be

1. Check that

var dest= companyhome.childByNamePath("Sites/jstest/documentLibrary/Approved");

returns an actual node. And

2. Make sure bpm_package exists (have you added this if you kicked the workflow off from code?) and that element 0 contains a node to move.