In the camunda modeler it is possible to map the result of a Business Rule Task in a process context attribute.
But is it also possible to map it into a complex object?
We tried to define an output parameter with a script, but it didn’t work:
${execution.setVariable("myObject.myAttribute, result)}
The linked examples show how the result variable of a Business Rule Task can be accessed in different ways.
But in my case this side of the mapping is not the problem.
In all linked examples the result is mapped into a flat attribute in the process context.
But in my case I want to map it into an complex object in the process context.
can you please provide an example that shows your use case?
Note that you map the result in any kind of process variable, for example:
<businessRuleTask id="businessRuleTask" camunda:decisionRef="myDecision">
<extensionElements>
<camunda:inputOutput>
<!-- store the internal decision result object to the variable 'result' -->
<camunda:outputParameter name="result">
${decisionResult}
</camunda:outputParameter>
</camunda:inputOutput>
</extensionElements>
</businessRuleTask>
or
<businessRuleTask id="businessRuleTask"
camunda:decisionRef="myDecision"
camunda:mapDecisionResult="resultList"
camunda:resultVariable="result" />
<!-- store the decision result as List<Map<String, Object>> to the variable 'result' -->
in my example I have an object “myObject” with the Attribute “myAttribute” in the process context of my BPMN process instance already when the process instance starts. In the first process step a Business Rule Task is called. The Business Rule Task Ends replies with a singleResult. Now we want the process instance to store this singleResult in the process context. We don’t want to store it as a simple/flat Attribute, but to map it into “myObject.myAttribute”.
Regarding your code snippets we don’t want to store “${decisionResult}” in “result”, but in “myObject.myAttribute”.
thank you for the description of your use case. Note that you can’t use execution.setVariable() to update only a field of a process variable. You have to update the field first and then update the variable.
For example, you can use an execution lister:
public class MyDecisionResultListener implements ExecutionListener {
@Override
public void notify(DelegateExecution execution) throws Exception {
DmnDecisionResult decisionResult = (DmnDecisionResult) execution.getVariable("decisionResult");
ProcessContext context = (ProcessContext) execution.getVariable("myObject");
String result = decisionResult.getSingleResult().get("result");
context.setDecisionResult(result);
execution.setVariable("myObject", context);
}
}
A configuration in the camunda modeler would be the optimal solution. But I read the limitations and understand that it is not possible because first the script configured in the camunda model is executed and after that the object is send to the camunda engine.