Show user who started the instance

987 views
Skip to first unread message

frank....@gmail.com

unread,
Jan 11, 2015, 10:03:12 AM1/11/15
to camunda-...@googlegroups.com
Hi there,

I'm a beginner with Camunda BPM and I just finished the Getting Started tutorial.

Now I wonder how it is possible to display the username of the user who started the process instance from within an embedded form.

Probably this is a quite easy thing, but I'm unable to figure out how to do it.

Is there any predefined variable-name I can use to access the username of the user who started the process instance?

Cheers
Frank

Sebastian Stamm

unread,
Jan 12, 2015, 4:43:25 AM1/12/15
to camunda-...@googlegroups.com
Hi Frank,

there is no pre-defined variable for the username of the user who started the process instance. However, you can easily create one yourself:

If you have a start form, you can access the id of the currently logged in user with $rootScope.authentication.name. You need to inject the $rootScope [1] per cam-script directive [2] and store the username in a cam-variable (e.g. using a hidden input field [3]). You can then access the variable in the embedded forms of the process.

Cheers
Sebastian

[1]: http://docs.camunda.org/latest/api-references/embedded-forms/#custom-javascript-available-api-inject
[2]: http://docs.camunda.org/latest/api-references/embedded-forms/#custom-javascript
[3]: http://docs.camunda.org/latest/api-references/embedded-forms/#supported-html-controls-hidden-input-fields-binding-a-hidden-element-to-a-process-variable

Roman Smirnov

unread,
Jan 12, 2015, 4:51:15 AM1/12/15
to camunda-...@googlegroups.com
Hi Frank,

There is no out-of-the-box solution for your problem, i.e. there is no build-in process variable or something in that direction.

Depending on how you start the process instance, you can submit the user name yourself. Assuming you use camunda Tasklist and embedded forms, you could implement a start form that automatically submits the name of the logged in user as a process variable.

Inside the form you are to execute your custom javascript [1], which could look like as follows:


<form role="form">

<script cam-script type="text/form-script">

inject([ '$rootScope', function($rootScope) {
// get variable manager
var variableManager = camForm.variableManager;

// current authentication to get the current logged in user
var user = $rootScope.authentication.name;

//
a new variable will add it to the form submit
variableManager.createVariable({
name: 'customVariable',
type: 'String',
value: name,
isDirty: true
});
}]);
</script>

// custom fields

</
form>
 

Please note: I did not test the snippet above.

Fell free to aks if you need assistance with that task. To do so, it would be good to know hou you start the process.

Cheers,
Roman

Frank Bitzer

unread,
Jan 12, 2015, 3:34:10 PM1/12/15
to camunda-...@googlegroups.com
Hi Sebastian and Roman,

thank you very much for your precise replies. I think both of you pointed out the solution in an understandable way.
However, I could not get it to work yet. The documentation says that using inject() requires the AngularJS integration. Is there anything special I have to configure to set up this integration?

I'm running basically the example app from the Getting Started tutorial and yes, I am using the Tasklist and a start task and a user task with an embedded form each. I want to set the username in the form belonging to the start task and then re-display it in the form which belongs to the next user task.

Btw when testing this out I ran in deployment or caching issues like described here: https://groups.google.com/d/msg/camunda-bpm-users/_bB0wxt4wy0/YKNV0HXsz_MJ
The engine is still delivering "old" forms even if I edit and re-deploy the process application several times.
Is there any general or recommended solution to this?

Cheers,
Frank

Frank Bitzer

unread,
Jan 12, 2015, 3:45:07 PM1/12/15
to camunda-...@googlegroups.com
Ok, thank you very much for your replies. I got this working using Romans script (there is just a little mistake. The line "value: name" should read "value: user").

Cheers
Frank
Reply all
Reply to author
Forward
0 new messages