How to get the current user ID?



I'm trying to get the current User ID from within the Edit Expression. Is there any API call that will return to me the user login ID from the session? I know you can do this via the UI Editor but how about within the Edit Expression?

Kindly guide me as I'm new to Bonita.


2 answers

This one is the BEST answer!


I use the Below Script to assign a task to a Specific User. This script is added to the Actor filter Section but you could use the Same inside the Edit Expression section. This script returns a User id .

I use the API ../API/system/session/ to get the username and store it inside a variable called demandReviewer .
you could check out the identity API for more information.

import org.bonitasoft.engine.api.IdentityAPI;
import org.bonitasoft.engine.identity.User;

IdentityAPI identity = apiAccessor.getIdentityAPI();
User user = identity.getUserByUserName(demandReviewer);

return user.getId();

hope this helps.


You can find the answer to this in the getting started tutorial

Create a variable in the UI with External API, ../API/system/session/unusedId

The content expression is {{session.user_name}}

When you create an external api variable, then there are a list of examples, so you can see the typical process related calls


Submitted by januah on Sat, 02/18/2017 - 02:17

Thanks for the reply. I'm aware of that API which can be called from the UI Editor but in my case I don't have a page because it's a service task not a human task. I can only work within the script editor with the available classes/packages. How can I achieve the same result?