- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2022 02:08 AM
Hello,
please, how to do:
one checkbox field be checked and mandatory , if the state of request changed to closed
thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2022 06:34 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2022 02:12 AM
Hi, you can write UI Policy to achieve it.
else you can write client script to achieve.
Can you use the code in client script onchange type
var state = g_form.getValue('state');
if (state == '6'){ // change it to Closed DB value
g_form.setMandatory('fieldname',true);
g_form.setValue('fieldname',true)
}
Please mark as correct answer/helpful if it answered.
Regards,
Suresh.
Suresh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2022 04:30 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2022 06:12 AM
You achieve in the script from UI Policy to set the as true.
and refer below link for further understanding. In the same link it provides info which one is best client script or UI policy.
https://developer.servicenow.com/dev.do#!/learn/learning-plans/quebec/new_to_servicenow/app_store_learnv2_scripting_quebec_exercise_create_ui_policies
Please mark as helpful/correct answer if it helped.
Regards,
Suresh.
Suresh.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2022 02:27 AM
Hi Bouzaabia
Checkbox can be either true or false. For this case making it mandatory won't work. So you check in the script whether the valued is "true" before "closing" the request and abort the request submission by showing a message "that checkbox need to be checked before closing the request" else allow request submission.
sample code for client script
function onSubmit() {
var checkbox= g_form.getValue("checkbox");
if (checkbox== 'false') {
g_form.addErrorMessage('Please check the checkbox');
g_form.showFieldMsg('check_box_name', 'Please check the checkbox', 'error');
return false;
}
}
Please mark helpful if resolved the query!