
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2022 09:04 AM
Hi Guys just seeing if this is possible as its failed and brings back undefined so far.
Example Glide Record below
var x = u_name
var grUser = new GlideRecord('sys_user);
grUser.addQuery('sys_id', '122344456666');
grUser.query();
if(grUser.next()){
var example = grUser.x;}
[This is a shortened version of what I'm trying to do by getting the column name and then adding it to the end of the gr Query to be the column name I'm trying to capture data from.]
Thanks in advance
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2022 09:40 AM
Hi Markell,
What you're trying to achieve is possible. I assume you're wanting to use a variable whilst passing through a loop of some sort.
The key with this approach is remembering when using GlideRecord that you're creating an object. With this object you can then dot-walk to fields or columns on the table. Please note however, the column needs to exist, otherwise you're likely to get a response of 'undefined'. See below example with slight tweak to your code.
(Tip - I tested this as a background script on PDI)
var x = 'name'; // column/field that exists on table (eg sys_user)
var grUser = new GlideRecord('sys_user');
grUser.addQuery('sys_id','62826bf03710200044e0bfc8bcbe5df1'); //sys_id of abel.tuter from Personal Dev Instance
grUser.query();
if(grUser.next()){
var example = grUser[x]; //x needs to be a column/field on the table and GlideRecord object. undefined would be returned using your example of x = 'u_name' as u_name does not exist (on a standard sys_user table)
}
gs.print('Example: ' + example);
To help others, please mark as correct and/or helpful.
Thanks,
Robbie

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2022 09:54 AM
Glad to know proposed solution worked for you. If both solutions are correct then you can prefer to mark first response as correct answer.
Happy learning 🙂
Anil Lande
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 02:32 AM
It wasn't personal. I gave t Robbie as his extra info helped me understand a bit more, but I was happy enough with you're input too. Can't please everyone lol