
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2023 12:23 PM
Hi Developers,
I have the objective to dynamically add options on the catalog item select box variable when a particular check box has been checked. In an attempt to achieve this objective, I have created a catalog client script (please see below):
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var gr_user = new GlideRecord('sys_user');
gr_user.addEncodedQuery('active=true^web_service_access_only=false^internal_integration_user=false^roles=timecard_approver');
gr_user.query();
while (gr_user.next()){
g_form.addOption('delegate', gr_user.getValue('user_name'), gr_user.getValue('name'));
}
}
The above catalog client script does not help me achieve my objective instead it produces the error below. Please assist.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2023 04:02 PM - edited 04-16-2023 04:09 PM
Hi @Kamva ,
May be it's because of addEncodedQuery, try using setEncodedQuery. Try with below script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var gr_user = new GlideRecord('sys_user');
gr_user.setEncodedQuery('active=true^web_service_access_only=false^internal_integration_user=false^roles=timecard_approver');
gr_user.query(respUser);
function respUser(gr_user){
while (gr_user.next()){
g_form.addOption('delegate', gr_user.getValue('user_name'), gr_user.getValue('name'));
}
}
}
And I don't think even this will return result, why because you are using roles attribute in your encoded query, which is not a valid field in sys_user table.
And you are not using the onChange variable value to take a decision in the script, which may cause few other bugs.
The best recommendation is to use GlideAjax with client Callable Script Include. Let me know if you need help on this approach.
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2023 04:02 PM - edited 04-16-2023 04:09 PM
Hi @Kamva ,
May be it's because of addEncodedQuery, try using setEncodedQuery. Try with below script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var gr_user = new GlideRecord('sys_user');
gr_user.setEncodedQuery('active=true^web_service_access_only=false^internal_integration_user=false^roles=timecard_approver');
gr_user.query(respUser);
function respUser(gr_user){
while (gr_user.next()){
g_form.addOption('delegate', gr_user.getValue('user_name'), gr_user.getValue('name'));
}
}
}
And I don't think even this will return result, why because you are using roles attribute in your encoded query, which is not a valid field in sys_user table.
And you are not using the onChange variable value to take a decision in the script, which may cause few other bugs.
The best recommendation is to use GlideAjax with client Callable Script Include. Let me know if you need help on this approach.
Anvesh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2023 10:41 PM - edited 04-16-2023 10:42 PM
Hi @Kamva
1.Why you are used catalog client script. You can use reference qualifier to achieve this one and add filter.
2.Regarding this issue please see the console log , It will help to identify exact issue.
Thanks,
Ramesh Kandhan