cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot get ServiceTasks and EndEvents description in listeners

pmesmeur
Champ in-the-making
Champ in-the-making
A model can contain ServiceTasks and EndEvents. If listeners are recorded in the engine, I can be notified of them via the function:
[java]
void ExecutionListener.notify(DelegateExecution execution);
[/java]

Moreover, the modeler allows to fill a "Description" for both ServiceTask and EndEvent.

What I would like is to be able to retrieve the "Description" field in my listeners.

I tried things like this, but in vain:
[java]
void ExecutionListener.notify(DelegateExecution execution) {
            String id = execution.getCurrentActivityId();
            Task t = execution.getEngineServices().getTaskService().createTaskQuery().taskId(id).singleResult();
            status = t.getDescription();
/// OR
            String id = delegateExecution.getId()
            Task t = delegateExecution.getEngineServices().getTaskService().createTaskQuery().taskId(id).singleResult();
            status = t.getDescription();
}
[/java]

Each time, I get a null Task. I have the impression to "beat about the bush". Can you please help me?

Thanks
4 REPLIES 4

vasile_dirla
Star Contributor
Star Contributor
I think the transaction is not committed yet and that's why you get null value for the task.
if you want to obtain the "description" you wrote in the modeller then maybe is better to take it from the BPMNModel.
<java>
   BpmnModel model = repositoryService.getBpmnModel(execution.getProcessDefinitionId());
</java>
If this answer is not helping you too much please provide a JUnit for this and then will be easier to help you.

pmesmeur
Champ in-the-making
Champ in-the-making
Thank you very much for this answer. I created the following function
[java]
    private String getStatus(DelegateExecution execution) {
        String status = "";

        try {
            BpmnModel bpmnModel = execution.getEngineServices().getRepositoryService().getBpmnModel(execution.getProcessDefinitionId());
            Process process = bpmnModel.getProcesses().get(0);
            FlowElement flowElement = process.getFlowElement(execution.getCurrentActivityId());
            status = flowElement.getDocumentation();
        }

        catch (Exception e) {
            /// nothing to do
        }

        return (status);
    }
[/java]
and it works good… almost good… as while taking the "Documentation" string from the model, the expressions (such as ${value}) are not interpreted. This current solution is perfect temporarily but I would certainly have to find how to solve this issue.

Philippe

vasile_dirla
Star Contributor
Star Contributor
yes, I expect to be so because the BpmnModel contains the model as it is defined in the xml.
if you want to evaluate an expression, you could do it like that:
<java>
     Expression expression = Context.getProcessEngineConfiguration().getExpressionManager().createExpression("${value}");
     Object value =   expression.getValue(execution)
</java>

pmesmeur
Champ in-the-making
Champ in-the-making
Yeah, it works great. Thank you very much
Philippe