Hi, everyone:
I have create a simple process via Modeler
, and I would like to send email notification with all variables information in each key event to users.
The process has 4 fields inside, requestor(String), goods_name(String), amount(Long), approved(Boolean)
.
In the first User task
, I put one TaskListener
on it and the Even type
is assigment
, listener type is Jave class
, name call some_package_name.SendMailToAssigneeListener
. This listener can get requestor, goods_name, amount
.
In EndEvent
part, I put one ExecutionListener
on it and the Even type
is end
, listener type is Jave class
, name call some_package_name.SendTaskEndMailListener
. When the whole process has been completed, this listener just can get requestor, goods_name, amount
instead of all variables.
But when I use eclipse to do some test via Junit, the ExecutionListener
seem haven’t invoke when process completed.
Here is the BPMN file: Purchase_test.bpmn (6.6 KB)
Below is ExecutionListener:
public class SendTaskEndMailListener implements ExecutionListener {
public void notify(DelegateExecution execution) throws Exception {
IdentityService identityService = Context.getProcessEngineConfiguration().getIdentityService();
HistoryService historyService = Context.getProcessEngineConfiguration().getHistoryService();
String requestor = (String) execution.getVariable("requestor");
User user = identityService.createUserQuery().userId(requestor).singleResult();
String executionId = execution.getId();
if (user != null) {
// Get Email Address from User Profile
String recipient = user.getEmail();
List<HistoricVariableInstance> list = historyService
.createHistoricVariableInstanceQuery()
.executionIdIn(executionId)
.list();
System.out.println("Start check VariableInstance...");
System.out.println("Variable list size========="+list.size());
for(int i=0;i<list.size();i++) {
HistoricVariableInstance hv = list.get(i);
String name = hv.getName();
String value = hv.getValue().toString();
System.out.println("name==="+name+", value==="+value);
}
}
}
}