I have a service task and configured a Java Delegate. From Java Delegate, i want to persist the collection type ArrayList. I’m getting exception when i try to store ArrayList.
List<String> list = new ArrayList<>();
list.add("camunda");
list.add("jbpm");
list.add("activiti");
list.add("flowable");
How to persist this list in Java Delegate/Listeners?
org.camunda.bpm.engine.ProcessEngineException: Unknown property used in expression: ${list}. Cause: Cannot resolve identifier ‘list’
at org.camunda.bpm.engine.impl.el.JuelExpression.getValue(JuelExpression.java:63)
at org.camunda.bpm.engine.impl.el.JuelExpression.getValue(JuelExpression.java:51)
at org.camunda.bpm.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior.resolveNrOfInstances(MultiInstanceActivityBehavior.java:107)
at org.camunda.bpm.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior.execute(MultiInstanceActivityBehavior.java:64)
code:
@Component("loggerDelegate")
public class LoggerDelegate implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) throws Exception {
log.info("Start -> Logger delegate to bypass the activity");
List<String> list = new ArrayList<>();
list.add("camunda");
list.add("jbpm");
list.add("activiti");
list.add("flowable");
execution.setVariable("list", list);
log.info("End -> Logger delegate to bypass the activity");
}
}
Looks like that exception is not being thrown from the code that creates the list, but a multi-instance somewhere in your process that expects the list variable to exist. Does that make sense in your process model?
Is the expression for the list used in a listener on the user task by any chance? And is that listener on the create event? Then the user task probably needs to be async before
I can set, suppose if i have asyncBefore or asyncAfter between any of the tasks, for the variable which was been set scope=transient, will be accessed in further tasks?
Consider this, i will set “list” as transient variable in payload service, following a service task which is marked as asyncBefore, still can i access the transient variable in MI task? I hope not, because whenever task entity is persisted, transient variables will be removed at save point.
It’s a silly mistake i made. Solved it by changing from List type to Collection type. After checking the code in MultiInstanceActivityBehavior.java found it
@Component("loggerDelegate")
public class LoggerDelegate implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) throws Exception {
Collection<String> list = new ArrayList<>();
list.add("camunda");
list.add("jbpm");
list.add("activiti");
list.add("flowable");
execution.setVariable("list", list);
}
}