Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Client Script // Check if Checkbox is true

Meloper
Kilo Sage

Hay i have two or more Checkboxes on a form. If one of these boxes are checked, the record has to change the state ......

if i use:

var check1 = g_form.getValue('u_br_used');
var check2 = g_form.getValue('u_script_include_used');
var check3....

if (check1 == 'true' || check2 == 'true') {}

it works!

 

If i use 

if ((check1  || check2) == 'true') {}

an only Checkbox2 ist checked it does not work...

 

why?

 

i only want to check if one of the boxes is checked and i dont want to write

 

check1 == 'true' || check2 == 'true' || check3 == 'true' || check4 == 'true' || .....

 

1 ACCEPTED SOLUTION

Hi,

The if statement requires expression to evaluate

when you say check1 it is just a value but when you say check1 == 'true' it is an expression which it would evaluate to either true/false

https://www.w3schools.com/js/js_if_else.asp

https://www.javatpoint.com/javascript-if

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Bharath Irukull
Giga Contributor

If it is a script include, we have to use

objectname.getValue('checkbox_field_name')==true