Map Business Rule Task result in process context object

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)}

Hi @KJH,

if you don’t want to use a predefined mapping function then you can also use a custom mapping of the decision result. See the User Guide for details.

Note that the result is stored in the (transient) variable decisionResult.

Does this answer your question?

Best regards,
Philipp

Hi @Philipp_Ossler,

thank you for your answer.

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.

Best regards,
Karl-Josef

Hi @KJH,

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' --> 

Please be aware of the limitations.

Best regards,
Philipp

Hi @Philipp_Ossler,

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”.

Best regards,
Karl-Josef

Hi @KJH,

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);
  }

}

Does this work for you?

Best regards,
Philipp

Hi @Philipp_Ossler,

yes, this looks good.

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.

Thank you for your help!

Best regards,
Karl-Josef