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

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron

Hi,

the expression should be evaluated as true/false; it requires expression and not the values

so it won't work so use

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

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

Thank you, can you please try to explain it in more detail?

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

Meloper
Kilo Sage

I used

https://developer.servicenow.com/app.do#!/api_doc?v=newyork&id=r_GlideFormGetBooleanValue_String

 

and

(checkBR || checkSI || checkAPI|| checkDS || checkNot || checkTable || checkCati || checkUGR || checkProp || checkOther)