Possible to get and set processVariables given bussinessKey?
Hi Minisha, yes you can retrieve a process instance via its Business Key. It is one of the parameters you can pass in with the REST API call. See: https://docs.camunda.org/manual/latest/reference/rest/process-instance/get-query/
Once you have the process instance id you can get, set, and modify the variables as needed using these REST APIs https://docs.camunda.org/manual/latest/reference/rest/process-instance/variables/
Joe
Well, the approach doesn’t work in all the scenarios though. For instance, the below piece of code was returning null in “task activation listener” when we start a process.
And When getting all the active task, there is no way to get the businessKey as businessKey is not linked to task.
FYI: I am using postgres with camunda
public ProcessInstance getProcessInstance(String bussinessKey) {
return runtimeService
.createProcessInstanceQuery()
.processInstanceBusinessKey(bussinessKey)
.singleResult();
}
These where the few scenarios I noticed. I am pretty sure, there could be more. Overall, its bit inconsistent
Hi Minisha, in the first scenario it seems the timing is a bit off. You can start a process with a business key but if you attempt to get it before you the process actually starts it may not be available. Like a chicken and egg scenario. You should be able to get the business key at any point in the process. Do you have an example process you can share? Using Postgres (or any database) does not matter.
Joe
This is the one I was trying to make it work.
i) I set process variable while starting the process. And in create case configured TaskListener that update the process variable. When I fetch the process variable with processInstanceId it does work though, so I am not sure if it is really a chicken egg problem. (only with bussinessKey it didnt work)
ii) I was trying to get all active task irrespective of the process and there is no bussinessKey attached to the task object which makes the code bit complex. In my experience with camunda so far, we cannot get businessKey from task object and there is no straight forward way isnt?
Hi Minisha, I’m not clear on when you’re trying to get the business key. How are you starting your process? REST? Java? Are you passing in the business key when you start the process? You’re then trying to get the key in a task listener at the start of ‘create case’?
Joe