The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How to access user info in a workflow script

Michael M1
Giga Expert

I have a catalog item where one of the variables is to select a user from sys_user table (workflow.variables.u_user).

How can I get the value of a custom date attribute (u_expires) of that user in the workflow?

If I enter the following variables into a log statement:

var current = workflow.variables.u_user;
var thename = current.getDisplayValue();  
var expy = gs.getUser().getUserByID('current').getRecord().getValue('expires');
var expy2 = gs.getUser().getUserByID('current').getEmail();

 

current displays a sys_id
thename displays the user's name correctly
expy is undefined 
expy2 is null

 

How can I access the variable from the sys_id?

9 REPLIES 9

Can you check what value are you seeing on catalog variable form under name field

find_real_file.png

 

If the vairable name is var_select then script should be

var expy = current.variables.var_select.u_expires

 

ryan_pope
Mega Guru

In a workflow activity, current is a system defined variable that would contain an object holding data about the RITM (or record this WF is running on). That might be causing some issues if you're trying to redefine a variable named current. If you try changing the name of your first variable in the snippet you posted, does that help at all?

Thanks I tried workflow.variables as well. 

It is just odd that if I have a sys_id in a WF variable that I cannot dot-walk it.

I had to end up doing this to get the user name:

var usys = gs.getUser().getUserByID(workflow.scratchpad.usernow);
var uname = usys.getRecord().getValue('user_name');

 

where workflow.scratchpad.usernow contains the sys_id.

but I cannot -for example- access

workflow.scratchpad.usernow.email

workflow.scratchpad.usernow.user_name

ryan_pope
Mega Guru

If using workflow.scratchpad, you would not be able to dotwalk, as I believe this just houses a string value (being the sys_id). When using something like current.variables.u_user, current is an object which is what allows you to dotwalk into fields within it.

A couple of things to try:

1) Instead of workflow.scratchpad, use current.variables.[the name of the variable on the cat item].[the field on the user record you're trying to access].

OR

2)  You could just use the workflow.scratchpad value and run a GlideRecord query, so:

var gr = new GlideRecord('sys_user');
var newVar = '';
if(gr.get(workflow.scratchpad.usernow)) {
     newVar = gr.[field you're trying to access on user record]
}

Requested for is coming from AD account.

The above will work for AD account.