ServiceNow Catalog item Client Script & Ui Policy conflicts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
If there are variables like "Region" & "Unit". Region is a Multiple choice type variable & Unit is a select box type of variable now based on the region & unit selection there is other variables which are 11 checkbox variables which should be mandatory & visible based on the selection of Region & unit & if its not selected then these checkboxes should not be visible on the catalog form. For this the On change of unit is already been implemented & tried through UI Policy also but the checkboxes after the selection of unit & region & then deselect those options. Clear Value script also implemented. if anybody is having some suggestions they are most welcomed. Thanks!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @PrajayT ,
It looks like the behavior is getting overridden because both the Client Script and UI Policy are trying to control the same fields. When multiple rules ttouch visibility/mandatory at the same time, the last one that runs wins — that’s why you’re seeing checkboxes show/hide unpredictably.
In cases where visibility + mandatory are dependent on more than one variable (your Region + Unit combo), UI Policies become difficult to manage cleanly. I’d move the whole logic into the onChange scripts of Region and Unit instead of splitting it between UI Policy + Clear Value script.
Handle everything in one place:
Set visibility
Set mandatory
Clear values when needed
Re-evaluate on both Region and Unit change
This way nothing conflicts, and you get consistent results every time.
P.S.: If this helped, feel free to mark my response as helpful.
Thank you,
Mahesh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
better to have 1 onChange catalog client script on Region and 1 on Unit variable.
Don't use UI policy as it will be confusing.
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Thank you for marking my response as helpful.
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @PrajayT
Yes, ui policies are great for simple logic, when you have two driving variables (Region AND Unit) determining the fate of 11 other variables, a script gives you better control over the "Else" (cleanup) logic.
You likely need two onChange Client Scripts:
-
One that runs when Region changes.
-
One that runs when Unit changes.(Actually, it's cleaner to have them both call a single shared function so you don't duplicate code.)
Related Script :function onChange(control, oldValue, newValue, isLoading) { if (isLoading) { return; } // 1. Get current values of BOTH variables var region = g_form.getValue('region'); // Replace with your variable backend name var unit = g_form.getValue('unit'); // Replace with your variable backend name // 2. Define your target checkboxes in an array for easy management var myCheckboxes = ['cb_option1', 'cb_option2', 'cb_option3', 'cb_option4']; // Add all 11 backend names here // 3. Define the specific condition for visibility // Example: Show if Region is 'APAC' and Unit is 'Finance' var isMatch = (region == 'apac' && unit == 'finance'); if (isMatch) { // SHOW and make MANDATORY for (var i = 0; i < myCheckboxes.length; i++) { g_form.setDisplay(myCheckboxes[i], true); g_form.setMandatory(myCheckboxes[i], true); } } else { // HIDE, make NON-MANDATORY, and CLEAR VALUE // Crucial: You must set mandatory false BEFORE hiding, or ServiceNow might throw an error for (var j = 0; j < myCheckboxes.length; j++) { g_form.setMandatory(myCheckboxes[j], false); g_form.clearValue(myCheckboxes[j]); // This ensures no "stale" data remains g_form.setDisplay(myCheckboxes[j], false); } } }Happy to help! If this resolved your issue, kindly mark it as the correct answer ✅ and Helpful and close the thread 🔒 so others can benefit too.
Warm Regards,
Deepak Sharma
Community Rising Star 2025