I need the User's Name not the Sys ID
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2014 10:03 AM
I am using an inbound email action to create a ticket from an email. I am looking to have the Short Description be "Some text" + Users Name that entered the request.
Below is my code please let me know what I need to do to get the Users name instead of the Sys ID.
// Sets the Contact Person to the user who put in the request
current.caller_id = email.subject.slice(40);
//Sets the Description to combine the recieved from and all text in the body of the email
current.description = "received from: " + email.origemail + "\n\n" + email.body_text;
//Sets the Short description to combine the Applicaiton and the user who entered the request.
// The user is set by using a GlideSystem method to show the users First and Last name instead of showing the Sys ID for the user
myUserObject = gs.getDisplayName();
current.short_description = "Allscripts Care Management Requested by " + gs.getDisplayName(current.caller_id);
Thanks, Darcy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2014 10:16 AM
Follow this link-
Getting a User Object - ServiceNow Wiki
and you can use below code
var myUserObject = gs.getUser();
myUserObject.getDisplayName();
If that doesn't work you may use gliderecord to fetch the record
var gr = new GlideRecord('sys_user');
gr.addQuery('user_id',current.caller_id);
gr.query();
//now fetch any fields you want
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2014 10:19 AM
I think you want gs.getUserDisplayName()
http://www.servicenowguru.com/scripting/user-object-cheat-sheet/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2014 10:57 AM
The code below worked a little better but I am looking to get the Full Name of the user in current.caller_id. It is currently giving the user that sent the email.
current.short_description = "Allscripts Care Management Requested by " + gs.getUserDisplayName(current.caller_id);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2014 10:44 AM
If email.subject.slice(40) is working to set current.caller_id, why couldn't you do it again (or store it in a variable and reuse it later)?
current.short_description = "Allscripts Care Management Requested by " + email.subject.slice(40);
Or you could do it like this (which is what I would probably do):
// Gets the user's name from the email and store it for reuse
var userName = email.subject.slice(40);
// Sets the Contact Person to the user who put in the request
current.caller_id = userName;
//Sets the Description to combine the recieved from and all text in the body of the email
current.description = "received from: " + email.origemail + "\n\n" + email.body_text;
//Sets the Short description to combine the Applicaiton and the user who entered the request.
// The user is set by using a GlideSystem method to show the users First and Last name instead of showing the Sys ID for the user
myUserObject = gs.getDisplayName();
current.short_description = "Allscripts Care Management Requested by " + userName;
I think your issue is trying to get it back from current.caller_id. That's a reference field, so it stores the sys_id. You pass the user's display name and a database query gets the user's sys_id and stores it. Then you try to get your display name back from that field, but it's already been converted to the user's sys_id.
I'm still not 100% sure what you're trying to do, so report back and let us know if any of our suggestions were helpful.