Which executes first ,UI policy action or UI policy script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2019 07:51 AM
When runnning ui policies ,which executes first ,whether UI policy action or UI policy script?
- 21,901 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2025 12:11 AM
Hello @Gopi22 ,
Please note that an alert() is executed immediately and essentially freezes the browser and all other scripts. On the other hand, a lot of the ServiceNow UI logic is running asynchronously.
So what happened in your example is that the UI Policy Action was triggered first (starting to make the field mandatory asynchronously), then the UI Policy Script was invoked and essentially interrupted what the Action was doing.
So as numerous others have already said, the execution order is UI Policy Action first, then UI Policy Script.
You can verify this replacing your alert() with "g_form.setMandatory(yourFieldName, false);". The field will end up being non-mandatory, meaning the script ran later.
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2025 07:29 AM
Hi @Robert H ,
I tested as you suggested and I confirm what you mentioned is right.
Learned something new today, Thank you ! 🙂
To @anyone who is looking for a confirmed answer here - UI Policy actions gets executed first and then the script.
Thanks,
Gopikrishnan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2025 12:59 AM
Hi @Rohith16
So try a scenario, create an UI policy on incident table, create an UI action to make description field mandatory, under when to apply -> priority is 1-critical. Also create a script in -> Execute if true section - alert("Description mandatory now for P1 incident").
Create an incident with this now, you'll notice that the alert runs first, then the description becomes mandatory, which suggests that - UI policy script runs first then the UI policy action runs.
Mark my answer as helpful if applicable.
Thanks
Naman Chaturvedi

