I need the User's Name not the Sys ID

dneedham
Kilo Contributor

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

9 REPLIES 9

Bhupinder1
Giga Expert

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


ahaz86
Mega Guru

dneedham
Kilo Contributor

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);


Shawn Dowler
Tera Guru

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.