UI Policy onCondition Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2017 09:03 AM
I'm having trouble configuring when a field is mandatory and when it is not using a UI Policy script. I have a field u_request_type on the form that the UI policy condition depends on. The UI policy should go into effect when certain options are selected in the u_request_type field. When the conditions are met, the UI policy should make the u_site_type field visible. The tricky part is that I need the u_site_type field to be mandatory for some options, but not mandatory for others. Below is the scripts I have:
Execute if true:
function onCondition() {
if (g_form.getValue('u_request_type') == 'Admin'){
g_form.setDisplay('u_site_type', true);
}
else if ((g_form.getValue('u_request type') == 'Access/Permissions') || (g_form.getValue('u_request_type') == 'How-To')){
g_form.setDisplay('u_site_type', true);
g_form.setMandatory('u_site_type', true);
}
}
Execute if false:
function onCondition() {
g_form.setDisplay('u_site_type', false);
}
The UI Policy condition is set to run whenever the u_request_type is one of Admin, Access/Permission, or How-To. So if any option other than one of those three is selected, the u_site_type field should not be visible at all. I should note that I have already tried getting it working using two separate normal UI policies: one for the mandatory options and one for the non-mandatory option, however they seemed to end up conflicting with each other. Any help here is greatly appreciated!
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2017 09:11 AM
What type of field is u_request_type? Is it a choice list, reference field?
if choice list, be sure to use the choice VALUE, not the label!
If it's a reference field, then you'll need to compare the sys_id or use getDisplayValue() to compare it to the string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2017 09:21 AM
It is a Choice List field. I have confirmed that I am using Values and not Labels.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2017 09:26 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2017 10:39 AM