cancel
Showing results for 
Search instead for 
Did you mean: 

moving a document to a folder

niranjan
Champ in-the-making
Champ in-the-making
Hi,

I designed a work flow in JBPM, i want to add java script code in the jbpm workflow where it should move the files to a specified folder, when it is deployed in the alfresco.

need an urgent help on this.

Thanks in advance,

Niranjan
9 REPLIES 9

davidc
Star Contributor
Star Contributor
Hi,

Alfresco javascript may be hooked into many points within a workflow (e.g. on entering or leaving a state, on transition etc).

All Alfresco javascript capabilities are available.  So, operations like copy, move, transform are all possible within advanced workflows.

Within a workflow there are many pre-defined variables which can be accessed in javascript e.g. the package of content items being routed through the workflow, the space where the workflow was initiated.

This is all documented at http://wiki.alfresco.com/wiki/WorkflowAdministration (How to develop your own advanced workflows).

In your case, lets say you want to move all content items in the workflow to a space called 'Approved' (found under the space where the workflow was started) when the transition 'approve' is signalled… the following simple script will do the job.

<transition name="approve" to="approved">
  <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
     <script>
        var dest = bpm_context.childByNamePath("Approved");
        for (var i = 0; i < bpm_package.children.length; i++)
        {
            bpm_package.children[i].move(dest);
        }
     </script>
  </action>
</transition>

Note:
bpm_context = the space where the workflow was started
bpm_package = the collection of content items being routed thru the workflow

Let me know how you get on - also, if you'd like to share a description of your workflow, that'll be useful too.

e-no91
Champ in-the-making
Champ in-the-making
Hi,

I know this is a long post, but may I know what is the example of bpm_package? I think I'm not getting any files moved because of it.

Thanks!

baby77
Champ in-the-making
Champ in-the-making
Hey i am using a writen js for my workflow but it doesn't working.
Is it possible to execute  this script to parallelreview_group_processdefinition.xml to move document to space Approved?

var dest = companyhome.childByNamePath("User Homes/Approved");

              for (var i = 0; i < bpm_package.children.length; i++)
              {
                   bpm_package.children.move(dest);
              }
I figure it out the problem is in the bpm_package but don't know how to change it to work.
Please need advise.

Tnx Smiley Tongue

baby77
Champ in-the-making
Champ in-the-making
Hey i need solution of some expert here.
I had read all documentation about advanced workflow but i still got a problem.When my workflow end document don't move to specific space.
I set permission in permissionDefinitions.xml to users,i dont know what else to do.What am i missing?
Please help me otherwise i will be forced to give it up wih searching and learning of alfresco.
I am so mad because i try everything what i know and what have you suggested.
Maybe i am not for open source. :?:

Thanks in advance.

baby77
Champ in-the-making
Champ in-the-making
Hey

i finally manage to do the move. Smiley Very Happy
I am also trying with the same js make a move to a rejected space but don't work.I only change the name of the space where to move.
Is is possible to do move on both approved and rejected task name?i don't understand why on approve work and on reject don't.
Someone with the same problem,maybe?

Thanks

hyperation
Champ on-the-rise
Champ on-the-rise
I am also trying to do the same thing.  Do you have any code that you can share?

Thanks
Smiley Happy

notherien
Champ in-the-making
Champ in-the-making
to move a document u cas use this code in ur process-definition
<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
         <!– Deplacement du fichier –>
         <script>
            var test = bpm_package;
            var doc = test.children[0];
            var nameUH= userhome.properties.name;
            var myNode = companyhome.childByNamePath("User Homes/"+nameUH+"/ur_espace");
            doc.move(myNode);
         </script>
      </action>

mandana
Champ in-the-making
Champ in-the-making
Hi There,

I am trying to do the same thing. I added the script as presented in this post to existing Alfresco workflow (wf:review) and redeployed this again. However either nothing happens or I get an exception. I have included my new xml file. Can you help me please.

Thanks,

<?xml version="1.0" encoding="UTF-8"?>

<process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="wf:review">

    <swimlane name="initiator" />

    <start-state name="start">
        <task name="wf:submitReviewTask" swimlane="initiator" />
        
      <transition name="" to="review"/>
    </start-state>

    <swimlane name="reviewer">
        <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
            <actor>#{bpm_assignee}</actor>
        </assignment>   
    </swimlane>

    <task-node name="review">

      
        <task name="wf:reviewTask" swimlane="reviewer">
         
            <event type="task-create">
                <script>
                    if (bpm_workflowDueDate != void) taskInstance.dueDate = bpm_workflowDueDate;
                    if (bpm_workflowPriority != void) taskInstance.priority = bpm_workflowPriority;
                   
                </script>
            </event>

        </task>

      <event type="node-leave">
            <!– Update the status to In Review when we enter this task –>
            <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                <script>
                var wf = bpm_package;
               var doc = wf.children[0];
               var path = doc.parent;
               var nameUH= userhome.properties.name;               
               //var myNode = companyhome.childByNamePath("User Homes/"+nameUH+"/ur_espace");
               var pa = space.childByNamePath("Pending Approval");
                     logger.log(pa+" and … "+doc.parent);
               var res = doc.move(pa);
                 </script>
            </action>
        </event>
      
        <transition name="approve" to="approved" >
        <transition name="reject" to="rejected" />
   </task-node>

    <task-node name="rejected">
        <task name="wf:rejectedTask" swimlane="initiator" />
       
       <event type="node-leave">
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
         <!– Deplacement du fichier –>
         <script>
            var wf = bpm_package;
            var doc = wf.children[0];
         //var path = doc.parent;
            var nameUH= userhome.properties.name;
            //var myNode = companyhome.childByNamePath("User Homes/"+nameUH+"/ur_espace");
            var re = space.childByNamePath("Rejected");
         doc.move(re);
           </script>
        </action>
     </event>
      <transition name="" to="end" />
    </task-node>

    <task-node name="approved">
        <task name="wf:approvedTask" swimlane="initiator" />
       
      <event type="node-leave">
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
         <!– Deplacement du fichier –>
         <script>
            var wf = bpm_package;
            var doc = wf.children[0];
         //var path = doc.parent;
            var nameUH= userhome.properties.name;
            //var myNode = companyhome.childByNamePath("User Homes/"+nameUH+"/ur_espace");
            var re = space.childByNamePath("Published");
         doc.move(re);
           </script>
        </action>
     </event>
      <transition name="" to="end" />
    </task-node>

    <end-state name="end" />

</process-definition>

rajanigupta
Champ in-the-making
Champ in-the-making
hiiiii
I am also trying the same thing.I have started advanced wrkflow in "Pending for approval space" and I wanted to move the document in "Approved"
folder after approval.
Please tell me where and what changes  should I made in the following script :!:  :!:



<?xml version="1.0" encoding="UTF-8"?>

<process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="wfSmiley Tonguearallelgroupreview">

    <swimlane name="initiator"></swimlane>

    <start-state name="start">
        <task name="wf:submitGroupReviewTask" swimlane="initiator" />
        <transition name="" to="startreview"/>
    </start-state>

    <node name="startreview">
        <action class="org.alfresco.repo.workflow.jbpm.ForEachFork">
            <foreach>#{people.getMembers(bpm_groupAssignee)}</foreach>
            <var>reviewer</var>
        </action>
        <event type="node-enter">
            <script>
                <variable name="wf_approveCount" access="write" />
                <expression>
                    wf_approveCount = 0;
                </expression>
            </script>
        </event>
        <transition name="review" to="review" />
    </node>

    <task-node name="review">
        <task name="wf:reviewTask">
            <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
               <actor>#{reviewer}</actor>
            </assignment>
            <event type="task-create">
                <script>
                    if (bpm_workflowDueDate != void) taskInstance.dueDate = bpm_workflowDueDate;
                    if (bpm_workflowPriority != void) taskInstance.priority = bpm_workflowPriority;
                </script>
            </event>
        </task>
        <transition name="reject" to="endreview" />
        <transition name="approve" to="endreview">
            <script>
                <variable name="wf_approveCount" access="read,write" />
                <expression>
                    wf_approveCount = wf_approveCount +1;
                 </expression>
            </script>
        </transition>
    </task-node>

    <join name="endreview">
        <transition to="isapproved" />
    </join>

    <decision name="isapproved">
        <event type="node-enter">
           <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
              <script>
                 <variable name="wf_reviewerCount" access="write"/>
                 <expression>people.getMembers(bpm_groupAssignee).length;</expression>
              </script>
           </action>
           <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
              <script>
                 <variable name="wf_requiredPercent" access="write"/>
                 <expression>wf_requiredPercent = wf_requiredApprovePercent;</expression>
              </script>
           </action>
           <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
              <script>
                 <variable name="wf_actualPercent" access="write"/>
                 <expression>wf_actualPercent = ((wf_approveCount * 100) / people.getMembers(bpm_groupAssignee).length);</expression>
              </script>
           </action>
        </event>
        <transition name="reject" to="rejected" />
        <transition name="approve" to="approved">
            <condition>#{wf_actualPercent >= wf_requiredApprovePercent}</condition>
        </transition>
    </decision>
              
    <task-node name="rejected">
        <task name="wf:rejectedParallelTask" swimlane="initiator" />
        <transition to="end" />
    </task-node>

    <task-node name="approved">
        <task name="wf:approvedParallelTask" swimlane="initiator" />
        <transition to="end" />
    </task-node>

    <end-state name="end"/>

</process-definition>