How to access definition key from within delegate

Hello,

I have a java delegate (and hence the execution object). I’d like to get the definition key (in modeler, the property is named Id) of the process model I’m in. Is it possible directly, i.e. without executing queries via the RepositoryService or similar?

Thanks!

You can try something like this:
((ExecutionEntity) execution).getProcessDefinition().key

1 Like

Thank you for the hint! Frankly said, I don’t quite like the fact that I have to downcast the value.

What I wanted to do is to find other instances of the same process model. For now, I just defined a constant holding the model key. I hoped to be able to do this in a generic way, without having to define a constant.

“I don’t quite like the fact that I have to downcast the value” - yeah, completely agree with you. That’s why we query repository service to get the ProcessDefinition object in our project. But c’mon, this is Camunda )) - clean design is for puppies. Rugged developers should suffer )).

If you don’t want to do the simple casting then you can navigate the public API with execution.getProcessEngineServices().getReportiryService().processdefintionquery().processdefinitionID(execution.getProcessDefinitionID()).single(). (Or something very similar to that)

This ~should just query from the deployment cache so it would be a in memory query.

1 Like

@Stepan_Mozyra, @StephenOTT thank you both! Since this code, while more generic, is harder to read, I’ll stay at my boring implementation :-).

1 Like