We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

if statement needs to evalutate checkboxes

levino
Giga Guru

Hi Team

 

basically if select box is not sap then users need to select atleast one checkboxe ' ccl,ccz,other ,entelar'

 

Please help me to fix my script 

 

Thank You

Levino

 

function onSubmit() {
   //Type appropriate comment here, and begin script below
   var entelar = g_form.getValue('entelar_egl');
   var other = g_form.getValue('other');
   var ccl = g_form.getValue('ccl');
   var ccz = g_form.getValue('ccz');
   var request = g_form.getValue('request_type');
   if((request != 'SAP Read-only') &&  (ccl == 'false' || ccz == 'false' || entelar == 'false' || other == 'false')){
	g_form.addInfoMessage("please make a selection");
		return false;
   }
}

 

1 ACCEPTED SOLUTION

@levino 

 

The condition needs to be tweaked so that it could check if at least one checkbox is checked. As of now, it is checking for all the checkboxes to be checked. Try with the condition as :

 

if((request != 'sap_read_only') &&  (ccl == 'false' && ccz == 'false' && entelar == 'false' && other == 'false'))
Thanks and Regards
Amit Verma

View solution in original post

8 REPLIES 8

vermaamit16
Kilo Patron

Hi @levino 

 

Could you please check if the value of the field request_type is 'SAP Read-Only'. I suspect that you are doing the comparison with the field label instead of value.

 

Thanks and Regards

Amit Verma

Thanks and Regards
Amit Verma

Hi Amit

i am using the value not the label

 

Thanks

Levino

@levino 

 

I tried to simulate your issue. I am able to make it work with the same On-Submit Client Script which you have shared. Can you please check if the variable which you are passing to the if block to check the condition i.e. request != 'sap_read_only' is the same as the question value as shown below :

 

AmitVerma_0-1722840521308.png

Your script is working as expected as shown below :

AmitVerma_2-1722840628583.png

 

 

Thanks and Regards
Amit Verma

levino_0-1722843954881.png