Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Catalog form

Ram012
Tera Contributor

One catalog form there is fields like 

 

Roll : Multiple choice (6 Choices)

Account : multiple choice  (3 choices)

 

Select Account filed : 2 and 3 choices select in the roll field should 1 to 5 choice visible the form .

 

I'm write the UI policy condition but it's not working.

 

Any idea please help me.

 

 

2 REPLIES 2

Akash4
Kilo Sage

Hello Amar,

You can try using onCondition True case in UI Policy script.

function onCondition() {
    var accountValue = g_form.getValue('account'); 
    if (accountValue == '2' || accountValue == '3') {
        g_form.setValue('roll', ''); 
        g_form.clearOptions('roll');

        g_form.addOption('roll', '1', 'Option 1 name');
        g_form.addOption('roll', '2', 'Option 2');
        g_form.addOption('roll', '3', 'Option 3');
        g_form.addOption('roll', '4', 'Option 4');
        g_form.addOption('roll', '5', 'Option 5');
    } 
}
Regards, Akash
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.

_Tushar Soni
Kilo Sage
Kilo Sage

Hello @Ram012 ,

Try this onChange Catalog Client Script if the UI policy isn't working::

Use this script if you have a fixed number of choices and prefer straightforward code

(function() {
    var rollValue = g_form.getValue('roll'); // Get the value of the Roll field
    var choicesToShow = ['1', '2', '3', '4', '5']; // Choices to show

    // If Roll field value is 2 or 3, show the Account field and set its choices
    if (rollValue == '2' || rollValue == '3') {
        g_form.setDisplay('account', true); // Show the Account field

        // Show or hide choices based on the choicesToShow array 
        for (var i = 1; i <= 6; i++) {
            g_form.setChoiceVisible('account', i.toString(), choicesToShow.indexOf(i.toString()) > -1);
        }
    } else {
        g_form.setDisplay('account', false); // Hide the Account field
    }
)(); 

 

If you found my response helpful, please consider marking it as "Helpful" or "Accept Solution." Thank you!