The CreatorCon Call for Content is officially open! Get started here.

UI Policies: Onload, Reverse, & Remove Options

Desmo
Mega Guru

Hello,

Wanted to get insight as to why certain UI policy conditions do not behave as I expect them to behave.

Here is the scenario:

  1. Form has Field A & Field B
  2. Form A is a choice field
  3. Form B is a choice field
  4. For B choices are dependent on Form A choices
  5. There is a UI policy to remove options [removeOption] from Field B when Field A  is 'Closed'
  6. When I select 'Closed' from Field A, all options are still visible on Field B. (I make a selection).
  7. Save the record.
  8. I select Field B and the options are removed.

My thinking is the condition is met, Field A is Closed. 

  • Why does Field A have to be saved before Field B options can be removed?
  • Why does changing the Field A from 'Closed' to something else; then back to 'Closed' negate the UI Policy?
  • Is there another method (i.e. Client Script) that is more effective at removing options consistently?

 

-Desmo

4 REPLIES 4

Kieran Anson
Kilo Patron

Hey Desmo,

Is this on the native UI? Can you copy your UI Policy logic so the community can review it? It's import to note that UI Policies can't execute on list field changes, this is noted in ServiceNow Fundamentals.

 

(My notes from nowLearning)

  • UI Policies can access all fields on a record, client scripts can only access the ones loaded (and possibly hidden on load). UI Policies can therefore be used with the advanced element to script requirements.
  • Conditions are only re-evaluated if a user manually changes a field on the form; if the change is made by the system it will not be rechecked. Use Data Policies, which are not scriptable, to manage the mandatory and read-only state of fields for records not changed on a form.
  • UI Policies cant:
    • Access a previous fields value
    • Execute on form save/submit/update
    • Execute on list field value changes

MrMuhammad
Giga Sage

In this scenario the best and OOB way is to use dependent fields without scripting. I have explained this on the below thread. 

https://community.servicenow.com/community?id=community_question&sys_id=f7dbbbcf1b8ad8106531ea89bd4b...

 

Thanks & Regards,

Sharjeel

 

 

Regards,
Muhammad

Field 2 is dependent on Field 1. But, I also need it to be dependent on another field. Since this is not possible, I'm trying to implement UI policy or client script.

In that scenario you should go for onChange/onLoad client script and inside that you can use removeOption() & addOption() as required. 

 

Thanks & Regards,

Sharjeel

Regards,
Muhammad