cancel
Showing results for 
Search instead for 
Did you mean: 

Getting Document Associated with a Task

ebell
Champ in-the-making
Champ in-the-making
So, I have a workflow, and within the workflow, there are task-nodes.  Now, I'm only ever running the workflow on a single document at any given time. 
However, I know that multiple documents can be tasked together. 
What I'm looking to do is to modify the aspects of the document during the task.
I can send emails, but I can't seem to change the aspects. 
I know that document doesn't work, but I don't know what to use instead.  Is bpm_package the right designator?  What should I be using? 

<task-node name="Review">
      <task name="blwf:corporateReview" swimlane="corporate" />
      <transition  name="approve" to="Approved">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
               <script>
                   bpm_package.removeAspect("bl:approvable");
                   bpm_package.addAspect("bl:approvable");
                   bpm_package.properties["bl:approved"] = true;
                   bpm_package.save;
               </script>
            </action>
      </transition>
      <transition name="reject" to="UpdateandResubmit" >
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
               <script>
                       var mail = actions.create("mail");
                       mail.parameters.to = initiator.properties.email;
                       mail.parameters.subject = "Document Rejected";
                       mail.parameters.from = "Corporate";
                       mail.parameters.text = "A document has been rejected. For more information refer to the comment part.";
                       mail.execute(bpm_package);
                 </script>
            </action>
       </transition>
   </task-node>
1 REPLY 1

ebell
Champ in-the-making
Champ in-the-making
So, I solved my own problem, but will leave the solution here for others…

<task-node name="Review">
      <task name="blwf:corporateReview" swimlane="corporate" />
      <transition  name="approve" to="Approved">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               <expression>
                  <![CDATA[
                     <import resource="/Inbox/Data Dictionary/Scripts/move-accepted-file.js">
                  ]]>
               </expression>
            </script>
            </action>
      </transition>
      <transition name="reject" to="UpdateandResubmit" >
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
               <script>
                       var mail = actions.create("mail");
                       mail.parameters.to = initiator.properties.email;
                       mail.parameters.subject = "Document Rejected";
                       mail.parameters.from = "Corporate";
                       mail.parameters.text = "A document has been rejected. For more information refer to the comment part.";
                       mail.execute(bpm_package);
                 </script>
            </action>
       </transition>
   </task-node>

Calls the following Javascript (Which is uploaded in the data documents space on the server)  Note, anyone executing this script needs adequate (coordinator) access to data documents. 

var files = companyhome.children;
var isThere=false;
for(var i=0; i<files.length; i++){
   isThere = false;
   for(var j=0; j<bpm_package.children.length; j++){
      if(bpm_package.children[j].name == files[i].name){
         isThere = true;
         break;
      }
   }
   if(isThere){
      if(companyhome.childByNamePath("_Approved") == null) {
         companyhome.createFolder("_Approved"); 
      }
      destination = companyhome.childByNamePath("_Approved");
      files[i].move(destination);
   }
}