Help with using g_form.addInfoMessage with GlideRecord in UI macro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2018 04:38 AM
My background isn't in scripting so I suspect my issue is probably pretty trivial.
Problem: I am using a "g_form.addInfoMessage" script within a UI macro but I cannot get the results from a gliderecord query to display in the info message.
Objective: I added a UI macro (button) to the new_call form that will get the caller's id, query a table, and display results in a new info message on the active form.
The current code will run the script, display the new info message, but the results from the query are not included. If I run the same code in a background script and print the results it returns values successfully, seeming to indicate the query is working.
function getrecords(reference) {
var user = g_form.getReference('caller');
var kbviews = new GlideRecord('kb_use');
var results = '';
kbviews.addQuery('user', user);
kbviews.query();
while (kbviews.next()){
results +=kbviews.getDisplayValue('article.short_description');
}
g_form.addInfoMessage(results);
}
Note: I know that the current code will poorly format the results if they were to display. However, for now I am just trying to get the data to display and will then worry about formatting.
Thank you.
Edit: It appears that the issue is with how the g_form.getReference is collecting the information. I modified the script to print the User value in the info message (to make sure I am getting that part successfully), and it prints the user value as [object Object]. If I use g_form.getReference('caller').user_name; it will successfully capture and print the username, but I need to get the sys id. If I try to use "...".sys_id it does not return a value.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2018 09:47 AM
try below
function getrecords(reference) {
var user = g_form.getReference('caller');
var kbviews = new GlideRecord('kb_use');
var results = '';
kbviews.addQuery('user', user);
kbviews.query();
while (kbviews.next()){
results += (kbviews.article.short_description);
}
g_form.addInfoMessage(results);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2018 10:04 AM
Thank you, Mike. However, this still resulted in a blank message.
I edited the original post to include a new finding.
"It appears that the issue is with how the g_form.getReference is collecting the information. I modified the script to print the User value in the info message (to make sure I am getting that part successfully), and it prints the user value as [object Object]. If I use g_form.getReference('caller').user_name; it will successfully capture and print the username, but I need to get the sys id. If I try to use "...".sys_id it does not return a value."

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2018 10:49 AM