How to check if a process definition key exist in camunda using services?

Viewed 927

I am trying to know if a process definition key exists in Camunda using its services.

I am aware of the rest api to fetch the details which is - GET /process-definition/key/{key}.

But instead of using rest calls, I would like to use the service's methods to achieve in my Java code.

2 Answers

Checke the RepositoryService. It will give you the createProcessDefinitionQuery method, which creates a Query builder that (among other attributes) accepts the process definition key.

Solution-

RepositoryService RS= execution.getProcessEngineServices().getRepositoryService(); ProcessDefinitionQuery processDefinitionQuery = RS.createProcessDefinitionQuery().processDefinitionKey("sample_key"); long count= processDefinitionQuery.count();

Related