I want to show the business key of the process instance in a user task as a read only field. I know how to use forms to show process variables with the ${variablename} pattern but the businesskey is no process variable. How do I reference the business key?
you can load the businessKey with Javascript via the REST-API. You would have to get the process definition id of the task first and then get the businessKey for that process instance.
The example for uploading large files has a code snippet that loads the process instance id.
I was hoping there is something more leightweight. Maybe a script function like execution.getBusinessKey()
I could use in a script-executionlistener the way one can use execution.setVariable(..., ...);
If there is no such function I could also store the value used as business key as an ordinary process variable as well and then access it with ${variableName}.
in your BPMN you can add an executionlistener for the event type “start” to your usertask. There you use e.g. javascript to read the businesskey and store it as a processvariable. It is a bit ugly to store the businesskey twice but this workaround did the trick for me.
//code not tested execution.setVariable("myBusinessKeyVariable", execution.getProcessBusinessKey());
Maybe there is another “setVariable” function that sets the scope of the variable only to the usertask, so the variable is destroyed after the usertask is completed.
You could also store the value of your businesskey as processvariable when starting a new processinstance. I start my process instances from the java api so this is easy work for me.
My current customer would prefer a client-side solution that does not involve a new process variable, because it takes extra space in the history. Ideally, they would like to reuse the cam-business-key Directive:
<!-- does not work ATM -->
<input type="text"
cam-business-key
readonly="true"
class="form-control" />
Does one really have to load the task in a separate request from the server to get the process instance id, i.e. is the task not already loaded by Tasklist, e.g. to show the assignee? If so, could camForm also provide access to the entire object and not just to camForm.taskId?
The more I think about it, the more I believe that Tasklist should generally display the business key in filter results as well as single task view, because it plays such an important role for many of our customers.
In order not to harm general performance for all task queries, we could handle it similar to the form key, which is only ‘joined’ to the task entity on demand.
in context of that, I am also surprised that the business key is not part in many REST based queries like in getting tasks. Don’t know if it make sense to open a new thread for it…
would also return the business key as the business key is the identifier in our landscape to identify the origin entity in context to the processDefinitionId. “If you know the processDefinitionId and the businessKey you know the origin (Initiator) of the camunda task.”
Now, we need to implement a workaround where business key is not really used, because it makes no sense to make another request for the processInstance to get just the business key. (We are currently already facing the issue that we need to ask for active tasks and the related variables separately).
In my opinion, the business key should be returned for any resource below a processInstance. So, tasks, activities, etc.