- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 06:35 AM
Hi All,
Below code is giving alert as undefined. Please help
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var requested_user_sysid = g_form.getValue('requested_for');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', requested_user_sysid);
gr.query();
gr.next();
alert(gr.name);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 06:43 AM
Hi Sachin,
GlideRecord won't work in service portal , Kindly use Glidereference or GlideAjax, you will find lot of examples, Also there is one mistake in code you need to use if(gr.next()) instead of direct gr.next(), Mark my answer as correct if that helps.
var requested_user_sysid = g_form.getValue('requested_for');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', requested_user_sysid);
gr.query();
if(gr.next());
{
alert()
}
Regards
Regards,
Musab

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 06:43 AM
Hi Sachin,
GlideRecord won't work in service portal , Kindly use Glidereference or GlideAjax, you will find lot of examples, Also there is one mistake in code you need to use if(gr.next()) instead of direct gr.next(), Mark my answer as correct if that helps.
var requested_user_sysid = g_form.getValue('requested_for');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', requested_user_sysid);
gr.query();
if(gr.next());
{
alert()
}
Regards
Regards,
Musab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 06:45 AM
Hi Sachin
It's not good practivce to use GlideRecord in client side scripting.
You can use getRefernce or GlideAjax
examples:
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP