Home

Most of the times while working on complex advance workflow in alfresco we come to a point where we need to implement complex business logic within workflow for particular task during particular transition.

For instance in Procurement workflow GRN (Goods Receive Notes) needs to be generated when goods are received then invoices needs to be generated for payment based on number of items received likewise multiple documents being generated as workflow progress.

Main purposes of workflows are to leverage business processes and streamline business flows. So, it would be really necessary to automate all complex workflow part.

Now to inject business logic or in other words to add behavior within alfresco JBPM workflow we have two options either to use Alfresco javascript snippets within process definition file or Action classes.

Alfresco Javascript injection is handy and fast approach but it cannot handle complex operations so they have to be used sparingly only for light operations like sending notification mail, moving of association content from one space to another etc..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<transition name="" to="completed">
     <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
       <script>
         if (wf_notifyMe)
         {
           var mail = actions.create("mail");
           mail.parameters.to = initiator.properties["cm:email"];
           mail.parameters.subject = "Adhoc Task " + bpm_workflowDescription;
           mail.parameters.from = bpm_assignee.properties["cm:email"];
          mail.parameters.text = "It's done";
           mail.execute(bpm_package);
         }
       </script>
     </action>
   </transition>

 

For handling complex logic Action class has to be used.

Steps to create Action class in alfresco

Step1:

Create Action class which extends JBPMSpringActionHandler class and implement your business logic within overridden method “execute”.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package org.test.bean;
   import org.alfresco.repo.workflow.jbpm.JBPMSpringActionHandler;
   import org.jbpm.graph.exe.ExecutionContext;
   public abstract class customActionListenerextends JBPMSpringActionHandler {
@Override
   public void execute(ExecutionContext context) throws Exception {
       // Business logic goes here. workflow properties can be accessed through “context” object
 
   }
 
   @Override
   protected void initialiseHandler(BeanFactory factory) {
       // Load repository services of alfresco which later can be used in execute method
       System.out.println("Initialize Handler");
   }
   }

Step2:

Entry of action class in Respective Workflow process definition file

1
2
3
4
5
6
7
<transition name="approve" to="approved">
     <action class="com.test.workflow.action.bean.customActionListener">
     </action>
</transition>

Step3:

Deploy Action class by bundling it in form of jar file

Step 4:

Restart alfresco server.

And you are done when you will execute this workflow you will be able to see java class being invoked when you reach to that task. This is very important and crucial part of jbpm workflow as to add complex behavior to workflow we often need to use this.

Looking for quality Alfresco Web Hosting? Look no further than Arvixe Web Hosting!

Publicités

Laisser un commentaire

Choisissez une méthode de connexion pour poster votre commentaire:

Logo WordPress.com

Vous commentez à l'aide de votre compte WordPress.com. Déconnexion / Changer )

Image Twitter

Vous commentez à l'aide de votre compte Twitter. Déconnexion / Changer )

Photo Facebook

Vous commentez à l'aide de votre compte Facebook. Déconnexion / Changer )

Photo Google+

Vous commentez à l'aide de votre compte Google+. Déconnexion / Changer )

Connexion à %s