Catalog UI Policy Clearing Values on OnChange – Need Best Approach
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
I have a catalog item (Item1) with 73 variables. Based on the selected Action, if Action = G, I need to display 6 specific variables.
I implemented this using Catalog UI Policy with Execute if true and g_form.clearValue('variable_name'). All these options are checked:
- Applies on Catalog Item view
- Applies on Catalog Tasks
- Applies on Requested Items
- On load
- Reverse if false
Since the UI Policy runs on both onLoad and onChange, values are being cleared when opening RITM or SCTASK.
Additionally, these 6 variables have nested dependencies (e.g., selecting one reveals 12 more, and selecting one of those reveals 3 more). For each level, I’ve written separate UI Policies with similar logic.
What I’ve tried so far:
- For onLoad, I wrote a Catalog Client Script that checks if a variable has a value. If yes, it shows the variable with its values; if not, it hides it. This works fine for RITM and SCTASK.
- The issue now is clearing values correctly on onChange without impacting existing data when records are reopened.
Question:
What is the best solution to handle dynamic visibility and value clearing on onChange, while preventing unwanted clearing on RITM/SCTASK load?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
UI policies should only be used for simple show/hide, readonly, mandatory etc
for nested dependencies and complex logic you should always use Client script which gives you full control and access to other variables in form.
main idea is to to separate “visibility on load” from “value clearing on change.”
💡 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
yesterday
Hi @Ankur Bawiskar ,
Thank you for the clarification! I understand that client scripts are better for handling complex logic and separating visibility from value clearing.
In my case, I need to clear dependent variable values on onChange for 73 variables. Does this mean I need to create 73 separate Catalog Client Scripts, or is there a more efficient approach to handle this scenario?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
73 variables on form is too huge and not recommended.
recommendations below
- Use Catalog UI Policies for show/hide/mandatory logic only; avoid enabling "Clear the variable value" for RITM/SCTASK contexts.
- Use Catalog Client Scripts (onChange) to clear values, but add if (isLoading) return; to skip clearing on RITM/SCTASK reopen.
- Centralize nested dependency logic in onChange scripts, guarding with load checks and variable existence.
- Use Variable Sets to simplify management and reduce duplication across items.
- For visibility, prefer .setDisplay() over .setVisible() to reclaim form space.
- Avoid adding the same variable to multiple UI Policies unless necessary
💡 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
yesterday
Hi Ankur,
Thank you for the detailed recommendations! I’ve implemented an onChange client script like this:
Could you please give me a small example or best practice for handling nested dependencies efficiently? For instance, when one variable has multiple dependent variables, and those dependents have further nested dependencies, how can I structure this without writing repetitive code for each variable?
