getting a sysid and using it to lookup a name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2010 09:30 AM
why won't this script use the sys_id returned by gs.getUserID()) to look up the name ?
it is displaying the message within the next loop, which tells me it found the sys_id, but the user name is blank.
var u=new GlideRecord('sys_user');
u.addQuery('sys_id',gs.getUserID());
u.query();
while (u.next() ) {
gs.log (" u.name:",u.last_name);
}
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2010 10:09 AM
Your log statement is wrong. It should probably read:
gs.log("u.name: " + u.last_name);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2010 10:13 AM
You can also simply by using a .get() like the following:
var u = new GlideRecord("sys_user");
if (u.get(gs.getUserID()))
gs.log("u.name: " + u.last_name);
And if you get the User object, there's already a method to return the last name, so to do this specific thing you could do it in one line:
gs.log("u.name: " + gs.getUser().getLastName());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2010 01:40 PM
Thank you ! so if I use "get" to pull a glide record I must use the get method, not a query method.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2010 02:08 PM
That's correct. 'get' eliminates the 'addQuery', 'query()' and 'next()' arguments completely from the query. It simply finds the single record and populates it in the variable.
SNCGuru has great cheat sheets on all of this information. It's not too difficult once you get the hang of a few concepts.
http://www.servicenowguru.com/tag/cheat-sheet/