- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2017 10:26 PM
In Performance analytic, I need to get the full name of the agent from the created_by field. And the script below doesn't seem work.
Any idea why?
function getUser(userName) {
var grUs = new GlideRecord('sys_user');
grUs.get('name',userName);
return grUs.getValue('sys_id') || '';
}
getUser(current.jour_sys_created_by);
**created_by is a string, not reference. Hence I am unable to use getDisplayValue.
**example: User id = admin; Full name = System administrator
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2017 10:29 PM
Hey,
The created_by field would be storing the user name and not the name. So your script should be like below.
function getUser(userName) {
var grUs = new GlideRecord('sys_user');
grUs.get('user_name',userName);
return grUs.getValue('sys_id') || '';
}
getUser(current.jour_sys_created_by);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2018 12:30 AM
Hi Everyone,
That is too easy -
gs.getUser().getUserByID('abel.tuter').getFullName();
This single line syntax can give you the required info rather going to define a function.
Here are more example usages of similar syntax:-
var fullname = gs.getUser().getUserByID('abel.tuter').getFullName();
gs.print("fullname : "+fullname);
var firstname = gs.getUser().getUserByID('abel.tuter').getFirstName();
gs.print("firstname : "+firstname);
var lastname = gs.getUser().getUserByID('abel.tuter').getLastName();
gs.print("lastname : "+lastname);
var email = gs.getUser().getUserByID('abel.tuter').getEmail();
gs.print(email);
var sysid = gs.getUser().getUserByID('abel.tuter').getID();
gs.print("sysid : "+sysid);
var userid = gs.getUser().getUserByID('abel.tuter').getName();
gs.print("userid : "+userid);
Output:-
*** Script: fullname : Abel Tuter
*** Script: firstname : Abel
*** Script: lastname : Tuter
*** Script: abel.tuter@example.com
*** Script: sysid : 62826bf03710200044e0bfc8bcbe5df1
*** Script: userid : abel.tuter
Thanks,
Saikiran Guduri
Associate Certification Engineer | ServiceNow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2021 04:06 AM
this line of code works when you know specific information. coding is to work when you know little to nothing.
this code is an ok test of an application's code prior to deployment.
TEST
var sysid = gs.getUser().getUserByID('abel.tuter').getID();
gs.print("sysid : "+sysid);
vs
DEPLOY
var sysid = gs.getUser().getUserByID(VariablePassedIn).getID();
gs.print("sysid : "+sysid);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2020 11:55 AM
You can use -
gs.log(gs.getUser().getUserByID(gs.getUserName()).getFullName());