- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 09:23 PM - edited 12-14-2022 09:27 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 11:43 PM
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**
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 10:02 PM
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**
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 10:52 PM
Hi @reshmapatil
It is working thanks,
but again when make the Questions 2 empty (not filled) it is not reverting back to mandatory field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 11:43 PM
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**
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 10:13 PM
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