cancel
Showing results for 
Search instead for 
Did you mean: 

Start workflow via JavaScript with the help of rules

fbehfar
Champ on-the-rise
Champ on-the-rise
Hi,
I want to create a rule, with the "execute a script" actions. I want to start the advanced workflow with the help of the rules.

Actually I want to automaticly start the workflow by adding a new content.

for example:
a user adds a content
the (whitepaper) workflow starts in backgroound and send a task for a specific users,
these users recieve a task on their pool tasks list.

Is it possible to start a workflow by defining a rule, at the time of adding a new content????
I guess one solution is to use the javascript in the rule definition, but how should the script look like?

Thank you,
FSB
34 REPLIES 34

witho
Champ on-the-rise
Champ on-the-rise
I finally could start my workflow and configure my own review workflow editing the file "review_processdefinition.xml" and changing the following property on the XML "bootstrap-context.xml"

bootstrap-context.xml



    <bean id="workflowBootstrap" parent="workflowDeployer">
        <property name="workflowDefinitions">
            <list>
                <props>
                    <prop key="engineId">jbpm</prop>
                    <prop key="location">alfresco/workflow/review_processdefinition.xml</prop>
                    <prop key="mimetype">text/xml</prop>
                    <prop key="redeploy">true</prop>
                </props>

My script finally looks like this:


var workflow = actions.create("start-workflow");
workflow.parameters.workflowName = "jbpm$wf:review";
workflow.parameters["bpm:workflowDescription"] = "Revision de documento.";
workflow.parameters["bpm:assignee"] = "p.user";
workflow.parameters["bpm:aproveDestination"] = "THEINIT/CLIENTES/APROBADOS";
workflow.execute(document);

And the "review_processdefinition.xml":


<?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">
            </event>
        </task>
        <transition name="reject" to="rejected" />
        <transition name="approve" to="approved" />
    </task-node>

    <task-node name="rejected">
        <task name="wf:rejectedTask" swimlane="reviewer"/>
        <transition name="" to="end" />
    </task-node>

    <task-node name="approved">
        <task name="wf:approvedTask" swimlane="reviewer"/>
        <transition name="" to="end" >
        <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
           <script>
               var dest = companyhome.childByNamePath(bpm_aproveDestination);
               for (var i = 0; i &lt; bpm_package.children.length; i++){
                  bpm_package.children[i].move(dest);
               }
           </script>
        </action>
      </transition>
    </task-node>

    <end-state name="end" />

</process-definition>

I hope this helps.

e-no91
Champ in-the-making
Champ in-the-making
Thank you so much! This one works for me!

e-no91
Champ in-the-making
Champ in-the-making
Thank you so much! This one works for me!

hyperation
Champ on-the-rise
Champ on-the-rise
Hi,

Does anyone know how I would be able to do the same with Java instead of with Webscript?

For instance, how would I start a workflow with multiple assignees?

workflowProp.put(whichPropertyName?, whatDataType?);

Thanks
Smiley Happy

amitkumar1
Champ in-the-making
Champ in-the-making
Hi,
  i am new to alfresco wanted to know where to put the javascript file in alfresco and how to add it in rule….

thnx,

kashyap_kk
Champ in-the-making
Champ in-the-making
HI,
   i have created a process definaation by modifying the review workflow and added a approve and reject destinations. when i start workflow by a rule and approve or reject it it does not move to the appropriate folders
my process defination file is


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

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

    <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">
            </event>
        </task>
        <transition name="reject" to="rejected" />
        <transition name="approve" to="approved" />
    </task-node>

    <task-node name="rejected">
        <task name="wf:rejectedTask" swimlane="reviewer"/>
        <transition name="" to="end" >
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
           <script>
               var dest = companyhome.childByNamePath(bpm_rejectDestination);
               for (var i = 0; i &lt; bpm_package.children.length; i++){
                  bpm_package.children.move(dest);
               }
           </script>
        </action>
      </transition>
    </task-node>

    <task-node name="approved">
        <task name="wf:approvedTask" swimlane="reviewer"/>
        <transition name="" to="end" >
        <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
           <script>
               var dest = companyhome.childByNamePath(bpm_aproveDestination);
               for (var i = 0; i &lt; bpm_package.children.length; i++){
                  bpm_package.children.move(dest);
               }
           </script>
        </action>
      </transition>
    </task-node>

    <end-state name="end" />

</process-definition>


and javascript

var workflow = actions.create("start-workflow");
workflow.parameters.workflowName = "jbpm$wf:reviewAndMove";
workflow.parameters["bpm:assignee"] = people.getPerson("amit");
workflow.parameters["bpm:aproveDestination"] = "Approved";
workflow.parameters["bpm:rejectDestination"] = "Rejected";
var futureDate = new Date();
futureDate.setDate(futureDate.getDate() + 7);
workflow.parameters["bpm:workflowDueDate"] = futureDate;
workflow.execute(document);


please Help….

kashyap_kk
Champ in-the-making
Champ in-the-making
hi
i am uploading my process defination file here

kashyap_kk
Champ in-the-making
Champ in-the-making
<?xml version="1.0" encoding="UTF-8"?>

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

    <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">
            </event>
        </task>
        <transition name="reject" to="rejected" />
        <transition name="approve" to="approved" />
    </task-node>

    <task-node name="rejected">
        <task name="wf:rejectedTask" swimlane="reviewer"/>
        <transition name="" to="end" >
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
           <script>
               var dest = companyhome.childByNamePath(bpm_rejectDestination);
               for (var i = 0; i &lt; bpm_package.children.length; i++){
                  bpm_package.children.move(dest);
               }
           </script>
        </action>
      </transition>
    </task-node>

    <task-node name="approved">
        <task name="wf:approvedTask" swimlane="reviewer"/>
        <transition name="" to="end" >
        <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
           <script>
               var dest = companyhome.childByNamePath(bpm_aproveDestination);
               for (var i = 0; i &lt; bpm_package.children.length; i++){
                  bpm_package.children.move(dest);
               }
           </script>
        </action>
      </transition>
    </task-node>

    <end-state name="end" />

</process-definition>

kashyap_kk
Champ in-the-making
Champ in-the-making

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

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

    <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">
            </event>
        </task>
        <transition name="reject" to="rejected" />
        <transition name="approve" to="approved" />
    </task-node>

    <task-node name="rejected">
        <task name="wf:rejectedTask" swimlane="reviewer"/>
        <transition name="" to="end" >
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
           <script>
               var dest = companyhome.childByNamePath(bpm_rejectDestination);
               for (var i = 0; i &lt; bpm_package.children.length; i++){
                  bpm_package.children.move(dest);
               }
           </script>
        </action>
      </transition>
    </task-node>

    <task-node name="approved">
        <task name="wf:approvedTask" swimlane="reviewer"/>
        <transition name="" to="end" >
        <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
           <script>
               var dest = companyhome.childByNamePath(bpm_aproveDestination);
               for (var i = 0; i &lt; bpm_package.children.length; i++){
                  bpm_package.children.move(dest);
               }
           </script>
        </action>
      </transition>
    </task-node>

    <end-state name="end" />

</process-definition>

kashyap_kk
Champ in-the-making
Champ in-the-making
HI,
i have created a process definaation by modifying the review workflow and added a approve and reject destinations. when i start workflow by a rule and approve or reject it it does not move to the appropriate folders
my process defination file is in above post
and java script is


var workflow = actions.create("start-workflow");
workflow.parameters.workflowName = "jbpm$wf:reviewAndMove";
workflow.parameters["bpm:assignee"] = people.getPerson("amit");
workflow.parameters["bpm:aproveDestination"] = "Approved";
workflow.parameters["bpm:rejectDestination"] = "Rejected";
var futureDate = new Date();
futureDate.setDate(futureDate.getDate() + 7);
workflow.parameters["bpm:workflowDueDate"] = futureDate;
workflow.execute(document);



please help