I was trying to run the below code in JavaScript Executor. but as an output, it returns "undefined".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2022 10:31 AM
I was trying to run the below code in JavaScript Executor. but as an output, it returns "undefined". any idea what I need to do??
gname = g_form.getValue('assignment_group');
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group',gname);
gr.query();
while(gr.next())
{
var user = gr.user.name;
alert(user);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2023 09:56 AM
Firstly, it is possible to call GlideRecord in client script (and @AnubhavRitolia response is not entirely right), but there is a specific way of how it can be used.
Though it can run synchronously, it is better to provide callback function as argument to the query() method, it then takes the resulting GlideRecord and process it.
Another issue in your case might be that client side GlideRecord does not support dotwalking, so this line in your code
var user = gr.user.name;
gives you undefined anyway.
I would recommend to get used to the debugger; statement and use it with together with browser's Developer tools so you can proceed your code step by step and inspect available variables.
I definitely do not recommend using alert() in your scripts in this way, especially not in loops, as its modal window stops all processing until manually closed by user, use console.log or jslog instead.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2023 01:08 PM
On top of the already correctly given answers, you are using 'from' as a variable. This is a protected variable, and as such cannot be used. Use fromTime for example as variable instead.
Based on what I see in your script, I highly suggest to use a GlideAjax call to do the most of your logic in a script include. There are a lot of things you want to do, which are a lot easier to do server side than they are to do client side.
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.