- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2023 08:31 AM
Hi,
Apologies if this is a simple issue, I am just beginning my developer journey!
I am trying to create a client script that will update a custom customer approvers field (list type) with users of the assignment group "ACME Change Approvers" when the "Technical Approver" field is changed, the company = 'acme' and the type = 'normal' but I am getting the following error with my script:
onchange script error: typeerror: cannot read properties of undefined (reading 'tostring') function () { [native code] }
Below is the script I have created:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var company = g_form.getValue('company');
var type = g_form.getValue('type');
if (company === 'acme' && type === 'normal'); {
var acmeGroup = new GlideRecord('sys_user_group');
acmeGroup.addQuery('name', 'ACME Change Approvers');
acmeGroup.query();
while (acmeGroup.next()) {
var approver = acmeGroup.member.toString();
g_form.addOption('u_business_approver', approver, acmeGroup.member.getDisplayValue());
}
}
}
Can you help with troubleshooting this error?
Thanks
James
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2023 08:36 AM
Hi James,
You can't perform a GlideRecord query from a client script. You're going to need to move the query to a Script Include and call the SI using GlideAjax.
GlideAjax Reference - https://developer.servicenow.com/dev.do#!/reference/api/tokyo/client/c_GlideAjaxAPI

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2023 08:36 AM
Hi James,
You can't perform a GlideRecord query from a client script. You're going to need to move the query to a Script Include and call the SI using GlideAjax.
GlideAjax Reference - https://developer.servicenow.com/dev.do#!/reference/api/tokyo/client/c_GlideAjaxAPI

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2023 08:41 AM
Your issue is this
var approver = acmeGroup.member.toString();
member is probably null.
You have to realize that the client side GlideRecord does not work the same way as the Server side one.
Docs are here
So you need to write your code like this
var approver = "" + acmeGroup.member;
or
var approver = acmeGroup.member;
or
var approver = acmeGroup.getValue("member");

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2023 08:45 AM
I also just noticed this
acmeGroup.member.getDisplayValue()
Using getDispalyValue only works on Service Portal, Mobile, and Agent Workspace and it has to be like this
acmeGroup.getDisplayValue("member")