How to make a variable visible/invisible based on another variable.

ramandeep
Kilo Contributor

Dear Friends,

I have a Catalog Item. There i have one check box type variable(Let us say abc) and two date type variables(let us say mno and pqr). I want if abc variable is checked then mno and pqr variables should be visible otherwise these(mno and pqr) should remain invisible. Can you please tell how can I achieve that?

Thank you

Ramandeep

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Ramandeep,



With screenshots


Screen Shot 2015-09-04 at 3.43.35 PM.JPG


Screen Shot 2015-09-04 at 3.43.41 PM.JPG


View solution in original post

13 REPLIES 13

poyntzj
Kilo Sage

Catalog UI Policy is preferred, but you may have to use a Catalog Client Script


Rushit Patel2
Tera Guru

Hi Ramandeep,



1.)make a UI policy. in condition field give condtion like if field ABC is false than hide those two fields using ui policy actions.


2.)now make a catalog on change(abc field) client script.write code like below.


if(g_form.getValue('abc') == 'true'){


g_form.setDisplay('pqr',true);


g_form.setDisplay('mno',true);


}




see if this helps.



Thanks,


Rushit Patel


Hi Rushil,



I have created below client script. Everything is going fine except one thing. When form is loaded then it displays mno and pqr. Now if I check and then uncheck abc then it hides these two fields. If I check abc again then it again shows mno and pqr. I want these 2 fields hide even when I open catalog item. Is creating Catalog UI Policy is the only option or I can do something in client script itself?



function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == 'true') {
g_form.setDisplay('mno', true);
g_form.setDisplay('pqr', true);
          return;
    }


else{
g_form.setDisplay('mno', false);
g_form.setDisplay('pqr', false);


}
    //Type appropriate comment here, and begin script below
   
}


HI Ramandeep,



Make sure that the OnLoad is checked in the UI policy you have created.


Please let me know if you have any questions.