- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2025 04:00 AM
Hi All
I seem to have an issue with this client script not executing correctly on a Catalog Item. The script is looking up a user on the sys_user table using a callback function. Then depending on if the field on the looked up user record has a value in it, will then make a variable on the catalog item hidden or visible. As it currently stands the form is hidding variables even when there is no entry on the looked up field, whereas it shoudl be displaying the variabIe.
Ithink i am missing something between each of the "if" statements. Can anyone assist?
//AM I MISSING SOMETHING TO SEPERATE THE ABOVE FROM THE BELOW "IF" STATEMENT
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2025 04:18 AM
Hi, I have found the issue. It was due to an ACL on the sys_user table, which prevented the results of the client script from being displayed. Thankyou for you assistance anyway, it was very kind of you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2025 11:45 PM
The above script doesnt work properly it just returns "undefined". I have tested that results are beign returned by the callback, by getting the result to populate a text field on the form. I have no other client scripts running on the cat item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2025 04:18 AM
Hi, I have found the issue. It was due to an ACL on the sys_user table, which prevented the results of the client script from being displayed. Thankyou for you assistance anyway, it was very kind of you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2025 04:36 AM
try this optimized code once
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.getReference('name_of_existing_colleague', callBack);
}
function callBack(usr) {
var fields = [
{ username: 'u_dunsaperpprodusername', field: 'sap_ecc_production' },
{ username: 'u_dunsaperppreprodusername', field: 'sap_ecc_pre_production' },
{ username: 'u_dunsaperpdev100username', field: 'sap_ecc_development_100' },
{ username: 'u_dunsaperpdev102username', field: 'sap_ecc_development_102' },
{ username: 'u_dunsaperpqausername', field: 'sap_ecc_qa' },
{ username: 'u_dunsaperpsandboxusername', field: 'sap_ecc_sandbox' },
{ username: 'u_dunsapewmprodusername', field: 'sap_ewm_production' },
{ username: 'u_dunsapewmpreprodusername', field: 'sap_ewm_pre_production' },
{ username: 'u_dunsapewmdevusername', field: 'sap_ewm_development' },
{ username: 'u_dunsapewmqausername', field: 'sap_ewm_qa' },
{ username: 'u_dunsapewmsandboxusername', field: 'sap_ewm_sandbox' },
{ username: 'u_dunsappoprodusername', field: 'sap_po_production' },
{ username: 'u_dunsappopreprodusername', field: 'sap_po_pre_production' },
{ username: 'u_dunsappodevusername', field: 'sap_po_development' },
{ username: 'u_dunsappoqausername', field: 'sap_po_qa' },
{ username: 'u_dunsapposandboxusername', field: 'sap_po_sandbox' },
{ username: 'u_dunsaphrprodusername', field: 'sap_hr_production' },
{ username: 'u_dunsaphrdevusername', field: 'sap_hr_development' },
{ username: 'u_dunsaphrqausername', field: 'sap_hr_qa' },
{ username: 'u_dunsaphrsandboxusername', field: 'sap_hr_sandbox' },
{ username: 'u_dunsapbwprodusername', field: 'sap_bw_production' },
{ username: 'u_dunsapbwpreprodusername', field: 'sap_bw_pre_production' },
{ username: 'u_dunsapbwdevusername', field: 'sap_bw_development' },
{ username: 'u_dunsapbwqausername', field: 'sap_bw_qa' },
{ username: 'u_dunsapbwsandboxusername', field: 'sap_bw_sandbox' },
{ username: 'u_dunsapbatchmanprodusername', field: 'sap_batchman_prod' },
{ username: 'u_dunsapbatchmanpreprodusername', field: 'sap_batchman_pre_production' },
{ username: 'u_dunsapbatchmandevusername', field: 'sap_batchman_dev' },
{ username: 'u_dunsapbatchmanqausername', field: 'sap_batchman_qa' },
{ username: 'u_dunsapsolmanprodusername', field: 'sap_solman_production' },
{ username: 'u_dunsapsolmandevusername', field: 'sap_solman_development' }
];
fields.forEach(function(item) {
if (usr[item.username]) {
g_form.setDisplay(item.field, false);
} else {
g_form.setDisplay(item.field, true);
}
});
// Special case for 'sap_solman_production' and 'active_control'
if (usr.u_dunsapsolmanprodusername) {
g_form.setDisplay('active_control', false);
} else {
g_form.setDisplay('active_control', true);
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2025 04:42 AM
Hi Ankur, thank for the script, but it is displaying variables that shoud be hidden as the call back field has a value in it
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2025 06:20 AM - edited 01-09-2025 06:24 AM
did you try to add alert for each field name?
are you sure the field names are correct?
the script I shared should work fine provided the field name is correct
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader