Workflows Question

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Active Member

Workflows Question

How can I execute a java code once a workflow is started ?
ExecutionListener is the solution ?
Any Examples ?

12 Replies
Highlighted
Partner

Re: Workflows Question

Hi,

in your BPMN definition you can define a start task like this:

<startEvent id="alfrescoStartevent" name="Alfresco start"
activiti:formKey="bpm:startTask">
<extensionElements>
<activiti:executionListener event="start"
class="your.java.class" />
</extensionElements>
<outgoing>flow1</outgoing>
<outputSet/>
</startEvent>

So when the workflow starts your java class will be executed. You class must

extends BoostedWorkflowListener implements ExecutionListener

and ovveride the

notify(DelegateExecution execution) 
Senior Member II

Re: Workflows Question

You can user activiti:executionListener when workflow start.

Ex.

<definitions>
<process id="id" name="name" isExecutable="true">
<extensionElements>
<activiti:executionListener event="start" class="com.workflow.StartWorkflowListener"></activiti:executionListener>
</extensionElements>
<startEvent id="startevent1" name="Start" activiti:formKey="wf:startProcess"></startEvent>
</process>
</definitions>

package com.workflow;
public class StartWorkflowListener  implements ExecutionListener {
@Override
public void notify(DelegateExecution execution) throws Exception {
}
}

Thanks & Regard,
Sanjay
Highlighted
Active Member

Re: Workflows Question

Thanks.
I created a bpmn file in this location \pfe\pfe-platform-jar\src\main\resources\alfresco\module\pfe-platform-jar\workflow
I pasted the process definition there, and I changed the class.

In the notify method I added a simple message to display System.out.println("hello");

and it didn't shows up.

I removed the extends WorkflowListener.

Are these the correct steps ?

Thanks.

Highlighted
Active Member

Re: Workflows Question

Thanks.

I added a System.out.println("hello"); in the notify function, and I got nothing.
I removed extends BoostedWorkflowListener because I didn't find from where to import it.
Any ideas ?

Highlighted
Partner

Re: Workflows Question

Yes,

sorry the BoostedWorkflowListener is a my class. You have only to implement

org.activiti.engine.delegate.ExecutionListener
Highlighted
Senior Member II

Re: Workflows Question

Are you able to start workflow?

Make sure that your class is accessible from bpmn file.

Thanks & Regard,
Sanjay
Highlighted
Active Member

Re: Workflows Question

Yes, that's what I did, and probably I'm still missing something. it didn't work out.
does it work with all kind of workflows ?
or with a custom one in your case related to the id="alfrescoStartevent", is it related to a custom process ?

Thanks.

Highlighted
Active Member

Re: Workflows Question

Yes, I started a simple new task, and the message wasn't displayed in the console.
and yes the class is accessible from the bpmn file.

here is my code :

bpmn file in the workflow folder :

<definitions>
<process id="MyProcess" name="My Process" isExecutable="true">
<extensionElements>
<activiti:executionListener event="start" class="com.pfe.listeners.DebutWorkflow"></activiti:executionListener>
</extensionElements>
<startEvent id="startevent1" name="Start" activiti:formKey="wf:startProcess"></startEvent>
</process>
</definitions>

and java class :

package com.pfe.listeners;

import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;


public class DebutWorkflow implements ExecutionListener {

@Override
public void notify(DelegateExecution execution) throws Exception {
// TODO Auto-generated method stub
System.out.println("hello");
}

}

Thanks.

Highlighted
Active Member

Re: Workflows Question

I tried to create a custom workflow and it worked. how can I use it on all types of workflow?
thanks