How to access to user information in script Task


#1

I would like to get the full name for a user in a script task (groovy) and set the value in the execution context. In activiti I could use userInfoBean to get the user info within a script task. Is there an equivalent I can use in flowable. What flowable beans are visible within a script task and how are they referenced? I have tried using identityService.getUserInfo(reviewer, “displayName”) but get error that identityService is not a known property. Many thanks for assistance.


#2

Hi Boneill,

In the case when you are looking for currently AuthenticatedUser:
https://www.flowable.org/docs/userguide/index.html#apiExpressions
authenticatedUserId: The id of the user that is currently authenticated. If no user is authenticated, the variable is not available.

In the other case use identity service to query for the user info. In the context of script task you can use
org.flowable.engine.impl.util.CommandContextUtil to get any service you want.

Regards
Martin


#3

Thanks Martin. Been away for a few weeks so thanking you now that I am back.


#4

Hi,
for anybody facing the same challenge, here is a groovy script example. If you copy&paste this, check if the quotes around admin are valid characters.

import org.flowable.engine.impl.util.CommandContextUtil;
def firstName = CommandContextUtil.getProcessEngineConfiguration().getIdentityService().createUserQuery().userId(‘admin’).singleResult().getFirstName()

Available methods for user object:

Available Queries for user search (i.e. query member of groups):