UI Policy onCondition Script

bradfournier
Kilo Expert

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!

10 REPLIES 10

Chuck Tomasi
Tera Patron

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.


It is a Choice List field. I have confirmed that I am using Values and not Labels.


What does the rest of the UI policy look like? Which script depends on the conditions field. I'm curious what table is used here and what the Conditions field looks like.



find_real_file.png


There are three Request Type options which should enable this UI policy (one is not shown, at the bottom of the list; "Admin Billable" is the label for the 'Admin' value).



uipolicy.png