Query sysID of user to retrieve user_name (User ID) value within Catalog Workflow

jlaue
Kilo Sage

Hello - 

I am using Advanced Script within a Catalog Task activity for a Service Catalog Item.  I am trying to set the Short Description to contain the User ID (user_name field from sys_user) from the Requested For variable that was populated on the Request Item.  

If I do this with the following code, I get the 'name' value, which is set as the Display Value for the sys_user reference field.  However, I need to get the user_name value displayed instead:

task.short_description = current.variable_pool.requested_for.getDisplayValue();

I am curious if I am able to do a GlideRecord query within the Advanced Script of the Catalog Task activity, and if so, what the code would be to get the user_name value.  I tried some variances of code that I found from researching this issue, but I am not having any luck:

var userid = current.variable_pool.requested_for;
var gr = new GlideRecord('sys_user');
gr.addQuery('user_name', userid);
gr.query();
if(gr.next()) {
var userName = gr.name;
}

task.short_description = userName;

 

 

Thanks in advance!!

 

 

 

 

1 ACCEPTED SOLUTION

Mike Patel
Tera Sage

do something like below; you don't need to query reference field, you can dot walk it.

task.short_description = current.variable_pool.requested_for.user_name;

View solution in original post

2 REPLIES 2

Mike Patel
Tera Sage

do something like below; you don't need to query reference field, you can dot walk it.

task.short_description = current.variable_pool.requested_for.user_name;

jlaue
Kilo Sage

Wow, wish I would have posted this an hour ago!   Thanks Mike!