which one will run first CS OR UI Policy

tghadage124
Tera Contributor

Hi Guys , 

 

In the service catalog which one will run first ui policy or client script ->

 

ans is dynamic actually : 

depends on the client script type :

if its on change client script then UI policy will run first then on change client script.
if its on load then first on load client script will run first then UI policy. 

 

Is the above ans correct ? what about other client script type is it same for them too 

its very imp interview question. 

 

please share the correct answer. 

 

thanks!!

2 REPLIES 2

Robbie
Kilo Patron
Kilo Patron

Hi @tghadage124,

 

To answer your question directly, the execution order is Client Script first then UI Policy.

UI Policies are recommended for use for this very reason as they're the last to load/execute reflecting what you see on the form.

Please note, to scratch the surface a little, there is an order field on both Client Scripts and UI Polices which helps you to control the execution order between scripts and UI Policies, but the hierarchy is still maintained between the 2 - UI Policies are last to run.

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.



Thanks, Robbie

Robbie
Kilo Patron
Kilo Patron

Hi@tghadage124,

 

Here's the link to the ServiceNow developer site confirming my above statement: UI Policies execute after Client Scripts. If there is conflicting logic between a Client Script and a UI Policy, the UI Policy logic applies.

 

https://developer.servicenow.com/dev.do#!/learn/courses/xanadu/app_store_learnv2_scripting_xanadu_sc...

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.



Thanks, Robbie