Show Business Key in Task Form

Hi,

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?

Thanks for any help.
Chris

Hi Chris,

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.

Does that help you?

Cheers
Sebastian

Thanks Sebastian,

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}.

Hi,

it exists a method getProcessBusinessKey on delegate execution if this helps.

Cheers,
Sebastian

Thanks a lot other Sebastian!

This did the trick. I use the executionlistener and set the businesskey as variable. This variable can be accessed in the formfield then.

Chris

Hi, I have the same problem but dont understand the solution. I see that camForm has a property businessKey, but it is ever null, even if set.

Can you provide a solution?
I can also read some variables, but how do I get the business Key?

 camForm.on('form-loaded', function() { 
      camForm.variableManager.fetchVariable('clientGroup'); 
 }); 
 camForm.on('variables-fetched', function() {  
       $scope.clientGroup = camForm.variableManager.variableValue('clientGroup'); 
 );
1 Like

Hi,

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.

I hope this answer can help you somehow.

Chris

1 Like

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" />

Is there a chance to make this work?

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.

2 Likes

Okay, I got it to work with JavaScript as described by @sebastian.stamm:

<form>
  <input type="text" 
             ng-model="processInstance.businessKey"
             readonly="true" />      

  <script cam-script type="text/form-script">
inject(['$http', 'Uri', function($http, Uri) {
  camForm.on('form-loaded', function() {
    $http.get(Uri.appUri('engine://engine/:engine/task/' + camForm.taskId)).success(function(task) {
      $http.get(Uri.appUri('engine://engine/:engine/process-instance/' + task.processInstanceId)).success(function(processInstance) {
        $scope.processInstance = processInstance;
      });
    });
  });
}]);
2 Likes

Hi,

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…

In my case it would be helpful if
https://docs.camunda.org/manual/latest/reference/rest/task/get/

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.

Best Regards,
Michael

5 Likes

I have this issue again with another customer. I tried it with JavaScript but camForm.businessKey is null.

Has this issue an easier solution already, like using the cam-business-key directive or camForm.businessKey mentioned above?

1 Like

It would make the most sense to have a directive to access the business key in embedded forms like we can access the process variables.