- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2018 12:07 PM
I have created a record producer with questions for our Service Catalog. It creates an incident and the answers to the questions are displayed in the incident description. I have a question of who to contact that is a list collector so multiple users can be selected.
My question is how to display the user name in the description field. I have the following coded:
'\nWho may we contact for more information? | ' + producer.u_contact
With this code, what displays is the sys_id for the user and I need it to show the user name instead.
Can someone tell me how to get this to work?
Thanks.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2018 02:21 PM
Cindy V,
You can add the function where you are using the line
'\nWho may we contact for more information? | ' + sysIdToUserId(producer.u_contact)
I also see that you figured out something on your own, which is good.
Just to clarify why I suggested you to use a function like that is for below reasons
1. The below code is wrong, you will get undefined as the return value not the User ID's
producer.u_contact.getDisplay();
2. The below code is right, probably the shortest way to do it
producer.getDisplayValue('u_contact');
3. The code in the above step will spit out the Display Value of the Sys_User table[which may not be the UserID all the time]. So you need a function that will return all the UserIDs explicitly.
-Please mark my answer as helpful/correct if applicable. Or else please dont 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2018 12:13 PM
See what happens when you use the getDisplay method:
producer.u_contact.getDisplay();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2018 12:22 PM
List Collectors store the comma separated list of sys_id in String format. So if you have a function like below that would intake the sys_id's from the list collector and return the User Id's back, that will solve your problem.
function sysIdToUserId(sysIdList)
{
var userIdArray =[];
var userGr = new GlideRecord('sys_user');
userGr.addQuery('sys_id','IN',sysIdList);
userGr.query();
while(userGr.next())
{
userIdArray.push(userGr.getValue('user_name'));
}
return userIdArray;
}
You can do something like
'\nWho may we contact for more information? | ' + sysIdToUserId(producer.u_contact)
Thank you,
Aman Gurram
Please mark the answer as correct/helpful if applicable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2018 12:54 PM
Thank you for the information. Where would I create the function? I am piece mealing this together to try to meet a change deadline 🙂
Is the function defined within the record producer, the variable (question) or ?
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2018 12:59 PM
The response from ccajohnson is the simplest and should work for you:
producer.u_contact.getDisplay();
It at least works against a GlideRecord. I hope it does on the producer object (not 100% sure what that is).