Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

UI Policy shows fields from previous selection — same field controlled by multiple UI Policies

beycos
Tera Contributor

Hi everyone,

I’m working on a form that has a choice field with 4 different options. Each option should display a different set of fields. To achieve this, I created 4 separate UI Policies, one for each option.

However, I’m running into a problem:

  • Some fields are included in more than one UI Policy Action

  • When I change the option, the fields from the previous UI Policy remain visible

  • Even if I disable Reverse if false, the issue continues

  • It looks like the UI Policies are overriding each other and not resetting the form correctly

My question: What is the correct way to handle this scenario when the same field appears in multiple UI Policies? Should each field only be controlled by a single UI Policy, and if so, what is the recommended structure for 4-option logic?

Any guidance or best practices would be greatly appreciated.

Thanks!

 
4 REPLIES 4

Tanushree Maiti
Tera Sage

Please refer this links:

 

https://www.servicenow.com/community/developer-forum/best-practices-for-ui-policies-where-multiple-f...

 

https://www.servicenow.com/community/developer-forum/multiple-ui-policies-on-the-same-field/m-p/1968...

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

SohamTipnis
Mega Sage

Hi @beycos,

 

You can achieve this by using a catalog client script; this approach will be easier than using UI policies for number conditions. Below is the script you can use; just put your field values in the script properly.

Let me know if this works!!!!😉

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) return;

    
    switch(newValue) {
        case 'option1':
            showFields(['field1','field2']);
            break;
        case 'option2':
            showFields(['field2','field3']);
            break;
        case 'option3':
            showFields(['field4']);
            break;
        case 'option4':
            showFields(['field1','field5']);
            break;
    }
}

 

 

If you find my answer useful, please mark it as Helpful and Correct. ‌‌‌‌‌‌‌😊


Regards,
Soham Tipnis
ServiceNow Developer ||  Technical Consultant
LinkedIn: www.linkedin.com/in/sohamtipnis10

Ankur Bawiskar
Tera Patron

@beycos 

better to go with 1 onChange client script instead of 4 UI policies

You can control the show/hide easily in that script

Please start with this and let us know

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

 

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

AndersBGS
Tera Patron

Hi @beycos 

 

I can see that you have created duplicated posts. Please see my response here: https://www.servicenow.com/community/developer-forum/ui-policy-is-not-working/m-p/3510250#M1250848

 

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/