Convert Given OnChange GlideRecord Client Script to GlideAjax so Script Works while Impersonating End User
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2022 08:40 AM
The following OnChange client script is being used for a catalog item I'm working on and works for admins but not for end users I try to impersonate while testing. I believe using a GlideAjax approach would work but I can't figure out how to convert this script to GlideAjax to achieve the same result. Please rescript and explain.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var user = new GlideRecord('sys_user');
user.addQuery('sys_id',newValue);
user.query(setOnBehalfDetails);
function setOnBehalfDetails(user) {
if(user.next())
{
g_form.setValue('user_id',user.user_name);
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2022 08:49 PM
Hi,
Yes. It should be Catalog Client scripts not a client scripts as you have to auto-populate the Catalog variables not a RITM fields.
Refer docs - Catalog client scripts
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2022 08:54 PM
Hello,
Question: are you using this for submission on a record producer/cat item to store the information for whom the record has been raised?
If so, the field in your resulting record might be populated after submission from elsewhere(workflow, flow, business rule). As such, even if you update the value front-wise, after submission, it might be even before insert due to a BR, the value gets changed.
Please also check this.
Tudor

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2022 10:43 PM
Hi Alantpham
I've tested the client side GlideRecord script in my instance and it works for both admin and non-admins.
If it's not working for non-admins, the problem is not because it's not using Scriplet Include.
Can it be that non-admin are opening the form from Service Portal? If so, UI Type should be set to "all" in Client Script.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2022 02:55 PM
Hi again,
Check the non-admin user has sufficient role to view Service Catalog form. That is, the user is able to navigator to the Service Catalog from home page. Then check if the user is able to view User table. Enter "sys_user.list" in Application Navigator to see if user list shows. If the user list does not show, it implies the user does not have sufficient privilege.
Then try changing the script as follows. When onChange is executed, it should show an alert message and if there is an error executing the script, it'll show an error message.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
alert("in onChange");
try {
var user = new GlideRecord('sys_user');
user.addQuery('sys_id', newValue);
user.query(setOnBehalfDetails);
function setOnBehalfDetails(user) {
if (user.next()) {
g_form.setValue('user_id', user.user_name);
}
}
} catch (e) {
alert(e.message);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2022 10:52 PM
Hi,
Few things to check
1) Is the script include function getting called for non-admins?
2) if yes then are they able to query sys_user table or not?
3) did you add getRowCount() to verify the count of record
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader