The CreatorCon Call for Content is officially open! Get started here.

Make single line text and select box field non mandatory if other single line text field is empty

gm6
Tera Contributor

Make single line text and select box field non mandatory if other single line text field is empty.

If question 1 and 2 are filled with values then question 5 and 6 fields should make to non-mandatory (optional) field

15.12.2022_10.49.40_REC.png

1 ACCEPTED SOLUTION

Try this

 

if (newValue == '' ||  g_form.getValue('que1') == ''){

g_form.setMandatory('que5',true);

g_form.setMandatory('que6',true);

}

if (newValue != '' && g_form.getValue('que1') != ''){

g_form.setMandatory('que5',false);

g_form.setMandatory('que6',false);

}

 

Regards,

Reshma

**Please mark my answer correct or helpful based on the impact**

View solution in original post

4 REPLIES 4

reshmapatil
Tera Guru

Hi @gm6 ,

 

You can achieve this by writing 2 Catalog Client Scripts:

1. OnChange of variable/ question 1 and write the below script:

if (newValue != '' && g_form.getValue('que2') != ''){

g_form.setMandatory('que5',false);

g_form.setMandatory('que6',false);

}

2.  OnChange of variable/ question 2 and write the below script:

if (newValue != '' && g_form.getValue('que1') != ''){

g_form.setMandatory('que5',false);

g_form.setMandatory('que6',false);

}

 

Regards,

Reshma

**Please mark my answer correct or helpful based on the impact**

gm6
Tera Contributor

Hi @reshmapatil 

It is working thanks,

but again when make the Questions 2 empty (not filled) it is not reverting back to mandatory field

Try this

 

if (newValue == '' ||  g_form.getValue('que1') == ''){

g_form.setMandatory('que5',true);

g_form.setMandatory('que6',true);

}

if (newValue != '' && g_form.getValue('que1') != ''){

g_form.setMandatory('que5',false);

g_form.setMandatory('que6',false);

}

 

Regards,

Reshma

**Please mark my answer correct or helpful based on the impact**

ServiceNow KT
Tera Expert

Hi 

Try using UI Policy Or Catalog UI Policy and set the condition as 
Field 1 is NOT Empty and Field 2 Is NOT Empty then Update the Policy actions as Field 5 and Field 6 as NON-Mandatory 

Let me know if you are facing any issues 

 

Regards

ServiceNow KT