on change client script using GlideRecord not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2024 02:55 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2024 05:53 AM
Issue: g_form is used in your script, but g_form is only available in client-side scripts, not in background scripts.
Solution: For background scripts, you should use gs.info() for logging output to the system logs or directly work with GlideRecord to query or update records
Script:
var grUser = new GlideRecord('sys_user');
grUser.addQuery('sys_id', '6816f79cc0a8016401c5a33be04be441');
grUser.query();
if (grUser.next()) {
gs.info('Email: ' + grUser.email);
gs.info('Location: ' + grUser.location.getDisplayValue());
gs.info('Department: ' + grUser.department.getDisplayValue());
}
If my answer helped you in any way, please then mark it as helpful or correct.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2024 06:03 AM
You should not be calling GlideRecord client side. It is best practice to create a client script that calls GlideAjax, which will then call a Script Include. In that Script Include, you will do any server side manipulation of the data you passed to it, then pass it back to the Client Script and do whatever you need based on the response from the Script Include. Here are some links that will help you get started with GlideAjax.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2024 06:27 AM
First of all you should not use GlideRecord in client scripts, if it is for Catalog items then use below method.
If it is for backend form like Incident form then you can simply dot walk 'Caller' field from from layout and bring Email,Location and departments fields and add to form without having to create custom fields.
If this is for learning purpose then use GlideAjax in client script like below
Regards,
Musab