As we transition to the new Hyland Community, some post links may be temporarily disrupted as we finalize redirects. We apologize for the inconvenience and are working to resolve this as quickly as possible. Details.
How can I execute a java code once a workflow is started ?ExecutionListener is the solution ?Any Examples ?
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)
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.I created a bpmn file in this location \pfe\pfe-platform-jar\src\main\resources\alfresco\module\pfe-platform-jar\workflowI 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.
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 ?
Yes,
sorry the BoostedWorkflowListener is a my class. You have only to implement
org.activiti.engine.delegate.ExecutionListener
Are you able to start workflow?
Make sure that your class is accessible from bpmn file.
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.
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.