Checkbox field checked by default

Bouzaabia
Tera Contributor

Hello, 

please, how to do:

 one checkbox field be checked and mandatory , if  the state of request changed to closed

thank you

 

1 ACCEPTED SOLUTION

Hello,

If my answer helped you please mark it as correct.

Thanks.

View solution in original post

10 REPLIES 10

ersureshbe
Giga Sage
Giga Sage

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.

Regards,
Suresh.

Hi  sureshloganathan

thank you 

but please how with UI policy!

because i have just those options !

ok for mandatory , but what about checked by default!

find_real_file.png

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

find_real_file.png

 

Please mark as helpful/correct answer if it helped.

Regards,

Suresh.

Regards,
Suresh.

Nishu Saini
Kilo Guru
Kilo Guru

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!