UI Policies: Onload, Reverse, & Remove Options

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2020 03:39 PM
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:
- Form has Field A & Field B
- Form A is a choice field
- Form B is a choice field
- For B choices are dependent on Form A choices
- There is a UI policy to remove options [removeOption] from Field B when Field A is 'Closed'
- When I select 'Closed' from Field A, all options are still visible on Field B. (I make a selection).
- Save the record.
- 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
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2020 03:56 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2020 03:58 PM
In this scenario the best and OOB way is to use dependent fields without scripting. I have explained this on the below thread.
Thanks & Regards,
Sharjeel
Muhammad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2020 08:05 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2020 10:07 PM
In that scenario you should go for onChange/onLoad client script and inside that you can use removeOption() & addOption() as required.
Thanks & Regards,
Sharjeel
Muhammad