Get Boolean Value for Fields - Client Script API
Import
·
Aug 04, 2022
·
article
Client Script API
When you do a g_form.getValue() on a checkbox type of field it will return a string type of value(true/false, typeof string). Instead use the getBooleanValue() for field with type as checkbox.
function onSubmit() {
var fieldChecked = g_form.getValue('field_name');
console.log(typeof fieldChecked); //String
var isChecked = g_form.getBooleanValue('field_name');
console.log(typeof isChecked );//Boolean
}
For nerds below if the actual definitions of the function
g_form.getBooleanValue(fieldName)
ƒ (fieldName) {
var val = this.getValue(fieldName);
val = val ? val + '' : val;
if (!val || val.length == 0 || val =="false")
return false;
return true;
}
Returns false if the field's value is false or undefined, otherwise trueis returned. Useful with checkbox fields Returns true when the checkbox is checked
View original source
https://www.servicenow.com/community/developer-articles/get-boolean-value-for-fields-client-script-api/ta-p/2303904