Setting Call Activity business key and "execution" instance

ENV: camunda 7.7.0, JDK 1.8, Springboot-1.5.7.RELEASE

We have a Call Activity modelled as following:

We have a logic to set Business Key based on:

  • Process Definition (key or id)
  • value of a specific process variable

In the model this logic is within the utility method: BpmExecutionSupport.businessKey, which reads exeuction.processDefinitionId and resolves the value of process variable “templateId”.

The problem we have here is the “execution” instance we passed is always the one of the defining process or the parent process.

  • We observed the business key value in database and realised that the subprocess is not yet started at that moment, so that it is not possible to obtain the subprocess’ “execution” instance.
  • We’d like to know how to obtain the “Process Definition” of the subprocess dynamically in this case?
  • Note that camunda can resolve the subprocess using " CalledElement Binding". Is there a way that we can also utilise this ability here? It will actually suffice if we can access the value defined under “Called Element”.

Surely we can pass the value under “Called Element” directly. But if possible we prefer to specify the value just once.

Found solution:
final FlowElement bpmnElement = exec.getBpmnModelElementInstance();
if (!BPMN_ELEMENT_CALL_ACTIVITY.equals(bpmnElement.getElementType().getTypeName())) {
throw new IllegalStateException(“businessKey can only be used on CallActivity”);
}
return bpmnElement.getDomElement().getAttribute(BPMN_ATTRIBUTE_CALLED_ELEMENT);

Awesome, thanks for sharing :slight_smile:

As an alternative to comparing the type and going via the DOM, you can check if bpmnElement is an instance of org.camunda.bpm.model.bpmn.instance.CallActivity. If true, cast it accordingly and use CallActivity#getCalledElement to access the called element.

Cheers,
Thorben

1 Like

The OOP way is better.

dude, I am sorry for bumping this relatively old post, but could you please elaborate on how your BpmExecutionSupport works. I want to pass business key based on custom logic and can’t figure out how and where I have to create this bean or whatever your BpmExecutionSupport is.

It’s all there. BpmExecutionSupport is just a normal bean defined in spring-context. The logic I used was described under the graphic. Combining all those plus your own logic you will have your solution. If not, you’re probably dealing with another problem.

Hmm, so it didn’t implement any particular interface or smth like that? I’ve tried creating simple bean:

@Component("foo")
public class TestBean {

    public String bar() {
        return "qwe";
    }
}

and setting business key expression to #{foo.bar()}. For some reason all I get is

2019-10-07T16:47:57,349 | ERROR | qtp1600528331-140 | context                          | 257 - org.camunda.commons.camunda-commons-logging - 1.4.0 | ENGINE-16004 Exception while closing command context: Unknown property used in expression: #{foo.bar()}. Cause: Cannot resolve identifier 'foo'
org.camunda.bpm.engine.ProcessEngineException: Unknown property used in expression: #{foo.bar()}. Cause: Cannot resolve identifier 'foo'
	at org.camunda.bpm.engine.impl.el.JuelExpression.getValue(JuelExpression.java:60) ~[246:org.camunda.bpm:7.8.0.alpha3-unitarius-karaf-4_2_4]
	at org.camunda.bpm.engine.impl.el.JuelExpression.getValue(JuelExpression.java:48) ~[246:org.camunda.bpm:7.8.0.alpha3-unitarius-karaf-4_2_4]

Just want to make sure I am not missing something stupid here.

Just a plain spring bean. Though I didn’t use explicit component name, i.e. testBean in your case. That exception has nothing particular to do with this topic, indicates rather general camunda usage problem.