Which one will runs first UI Policy action or UI Policy script

Arjun25
Tera Contributor

I believe UI Policy Scripts run first am i right????

28 REPLIES 28

Jason Thornton
Tera Contributor

Don't confuse UI Policy Scripts with Client Scripts. They are not the same thing.

 

"UI Policy scripts use the client-side API to execute script logic based on whether the UI Policy condition tests true or false. Use UI Policy scripts to create complex conditional checks or to take actions other than setting field attributes (mandatory, read-only, or visible).

The scripting fields for UI Policies are only visible in the Advanced view. To enable the scripting fields, select the Run scripts option.

  • The Execute if true script executes when the UI Policy condition tests true.
  • The Execute if false script executes when the UI Policy condition tests false."

https://developer.servicenow.com/dev.do#!/learn/learning-plans/quebec/new_to_servicenow/app_store_le...

Narendranath R1
Tera Contributor

If condition evaluates to true, UI Policy Action executes first then UI Policy Script.

Tested myself by setting a field mandatory via ui policy action on a condition and setting the same field not mandatory in the script execute if true part. The field was not mandatory after the ui policy is executed.

jay97
Tera Contributor

Hello There, 


I have tested it 

 

UI policy script will run first then UI policy actions will run

Mahesh Baraskar
Mega Guru

UI Policy action executes before the UI policy script.

 

You can test it by creating UI policy on the form for a particular field, e.g. category on incident form.  In that, write UI policy script and create one UI Policy action.  Then, go to Preferences->Developers->Click on JS Log and Field watcher, make it true.  Then, you can Field Watch the category on incident form.  You will see the execution order clearly in Field Watcher. 

 

You can refer to the screenshot attached herewith.

UI policy.PNG