How to access user info in a workflow script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2019 08:43 AM
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?
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2019 02:59 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2019 05:37 PM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2019 05:41 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2019 05:50 AM
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]
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-14-2021 04:24 AM
Requested for is coming from AD account.
The above will work for AD account.