- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2020 04:36 AM
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' || .....
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2020 05:13 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2020 04:51 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2020 05:02 AM
Thank you, can you please try to explain it in more detail?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2020 05:13 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2020 05:28 AM
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)