UI Policy for True/False variable is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2022 11:09 PM
Hi all,
i have a True/False variable in custom table, one ui policy is show and mandatory it when another field is selected as Yes. However, no matter how i click the checkbox, the asterisk next to it is always gray, i checked the XML data, it shows false and there is no default value.
Has anyone experienced a similar situation or can anyone provide a solution? thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2022 11:27 PM
Hi
Although you can "make" a True/False field (checkbox) mandatory, it always contains a true or false value so it will always be considered to be filled in regardless of the status. That's why you see the grey star - it's mandatory AND "filled in".
That is the reason many developers use dropdown with TRUE/FALSE and keeping NONE option which we can make mandatory through UI policy.
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2022 11:40 PM
Hi,
That is the default behavior of how Checkboxes in ServiceNow platform works.
To understand this better, when ever a mandatory field or variable is shown it is shown as Asterik in Red color.
When you fill out the value of that field or variable, Red color asterik change to grey color.
In case of check boxes, it always has a value as "false" by default since it store it as a Boolean type.
So default value of checkboxes are false by logic across any technology can be javascript or something else, that is the reason it is showing as in Grey color.
If you want to do a validation on checkboxes, I would suggest you can go with a catalog client script as an On Submit to validate this
For example:
function onSubmit() {
//Type appropriate comment here, and begin script below
var check1 = g_form.getValue('CheckboxVariablename');
if(check1 == ''){
g_form.addErrorMessage('Your messgae');
return false;
}
}
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke