set field mandatory in catalog for a select box variable

Amit Dey1
Tera Contributor

Hi , I have a requirement that a variable tto be mandatory upon selection of any value for that select box  variable and variable to become non-mandatory again if value is  none . so , I have written below onchange catalog client script but variable is showing mandatory even when setting the selectbox value to none .

if (newValue != "") {
g_form.setMandatory("cat_variable_name", true);
}
if (newValue == "") {
g_form.setMandatory("cat_variable_name", false);
}

Please help me in this matter .

thanks & regards 

1 ACCEPTED SOLUTION

Sagar Pagar
Tera Patron

Hi @Amit Dey1,

 

You can easily achieve using Catalog UI policy.

 

Condition as -

select_box_variable ISONEOF select all values -- (except - None)

 

UI policy actions - 

cat_variable_name -->  Mandatory ---> True

 

OR 

Try this updated scripts - 

 

if (newValue == "") {
g_form.setMandatory("cat_variable_name", false);
}
if (newValue == "value1" || newValue == "value2" || newValue == "value3"  ) {
g_form.setMandatory("cat_variable_name", true);
}

 

 

 

Thanks,
Sagar Pagar 

The world works with ServiceNow

View solution in original post

4 REPLIES 4

Sagar Pagar
Tera Patron

Hi @Amit Dey1,

 

You can easily achieve using Catalog UI policy.

 

Condition as -

select_box_variable ISONEOF select all values -- (except - None)

 

UI policy actions - 

cat_variable_name -->  Mandatory ---> True

 

OR 

Try this updated scripts - 

 

if (newValue == "") {
g_form.setMandatory("cat_variable_name", false);
}
if (newValue == "value1" || newValue == "value2" || newValue == "value3"  ) {
g_form.setMandatory("cat_variable_name", true);
}

 

 

 

Thanks,
Sagar Pagar 

The world works with ServiceNow

Hi Sagar , that UI policy worked , thank you

Hi @Amit Dey1,

Glad it help you!

 

Thanks,
Sagar Pagar

The world works with ServiceNow

Gummagatta Hars
Mega Guru

Hi Amit,

 

This requirement can be achieved by using the Catalog UI Policy. Kindly refer the below screenshot for the Catalog UI Policy and Catalog UI Policy actions. 

GummagattaHars_0-1667020180918.png

Kindly mark this answer as helpful if it has resolved the issue.

 

Thanks,

Harsha