How to run UI Policy onchange?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2019 10:58 AM
My UI policy(the conditions are shown bellow) runs correctly the first time the conditions are met. However, it is not running when I change the value of one of the fields. The only way to run it again is to delete the content of one of the fields, then click outside the box (I assume this sets the condition to false) then I can add new text to the field and the UI Policy finally runs again. How can I run the UI Policy every time the user changes the value of one of the fields, without the need to delete the content first? I am trying to avoid the onchange method because I would need an onchange for every field I have, and I don't think that it would be best practice.
- Labels:
-
Cost Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2019 11:07 AM
Select on Load check box to run it everytime some changes are made on the form and matches the conditions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 01:09 PM
This isn't working for me. I have the "On load" checkbox checked but it doesn't seem to work whenever I change the date field. It works the first time and after that only if I click on a different date that doesn't match the condition and then click on a date that again matches the condition it will run the script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2021 12:39 PM
I was going to say that one way to do this is with 2 UI policies, one that runs under Condition 1, and another that runs on Condition 2, but both do the same thing. This is best for running onChange of 1 field, but only if the field is a Choice or Reference field -- doesn't really work for String field.
But that's not your situation, since your condition has a lot of ANDs, and string fields, plus you want to run the policy every time any of the fields in the condition change.
You probably need to call g_form.onUserChangeValue in an `onLoad` client script. This will register an event listener that runs a client script any time *any* field changes on the form.
https://developer.servicenow.com/dev.do#!/reference/api/rome/client/c_GlideFormAPI#GF-onUserChangeValue_F?navFilter=glideform