Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Error message when the checkbox is false

nikhitha24
Tera Guru

Hi All,

 

Can someone please help me on the below query.

nikhitha24_0-1700982318037.png

In the options checkbox i don't want to be mandatory, but when checkbox is false need to thrown an error message to select the checkbox.

 

function onSubmit() {
var application = g_form.getValue('application_services_stopped');
if (application == '') {
g_form.addErrorMessage('Confirmation required: I confirm that application services hosted on these server(s) have been stopped and disabled/removed, and the server is powered on.');
return false;
}
return true;
}
I have written the above script, it is not working.
Please help me on this.

 

1 ACCEPTED SOLUTION

Danish Bhairag2
Tera Sage

Hi @nikhitha24 ,

 

Plz update ur script with below script

 

function onSubmit() {

var application = g_form.getValue('application_services_stopped');

if (application == 'false' || application == false ) {

g_form.addErrorMessage('Confirmation required: I confirm that application services hosted on these server(s) have been stopped and disabled/removed, and the server is powered on.');

return false;

}else{

return true;

}

}

 

Thanks,

Danish

 

View solution in original post

2 REPLIES 2

Sagar Pagar
Tera Patron

Hi @nikhitha24,

 

Try to update your scripts as sample scripts below and let me know.

 

Sample script:

function onSubmit() {

	var check_box1 = g_form.getValue('check_box1');
	var check_box2 = g_form.getValue('check_box2');


	if (check_box1 != 'true' || check_box2 != 'true') {
		g_form.addErrorMessage('Confirmation required: I confirm that application services hosted on these server(s) have been stopped and disabled/removed, and the server is powered on.');
		return false;
	}
}


If my response helps you resolve your issue. Kindly mark it as helpful & correct. It will be helpful to future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow

Danish Bhairag2
Tera Sage

Hi @nikhitha24 ,

 

Plz update ur script with below script

 

function onSubmit() {

var application = g_form.getValue('application_services_stopped');

if (application == 'false' || application == false ) {

g_form.addErrorMessage('Confirmation required: I confirm that application services hosted on these server(s) have been stopped and disabled/removed, and the server is powered on.');

return false;

}else{

return true;

}

}

 

Thanks,

Danish