Which runs first client script or ui policy?

KS86
Tera Contributor

As I know Client Script runs first, but 'If there is conflicting logic between client script and ui policy , the ui policy logic applies'. Can anyone explain the above sentence with examples? 

4 REPLIES 4

J Siva
Tera Sage

Hi @KS86 

In ServiceNow, client scripts run first when a form is loading on the browser, while UI policies execute after the form has fully loaded.

For example:

You have a client script that sets a field as mandatory, while a UI policy simultaneously attempts to make the same field non-mandatory, creating a conflict.

In this scenario, the client script initially enforces the mandatory requirement. However, when the UI policy logic is applied, it overrides the client script, making the field non-mandatory.

Ultimately, the UI policy logic takes precedence.

 

Hope this helps.

Regards,

Siva

Juhi Poddar
Kilo Patron

Hello @KS86 

You're right that Client Scripts typically run before UI Policies on form load. However, when there's conflicting logic between the two — for example, one sets a field to read-only and the other makes it editable — the UI Policy takes precedence.

Example

Let’s say you have a field called priority.

  • Client Script:
g_form.setReadOnly('priority', true);

 This makes the field read-only.

  • UI Policy:

You configure a UI Policy that makes priority editable when category == inquiry.

Result:

Even though the Client Script ran first and made priority read-only, the UI Policy overrides that and makes it editable (if the condition is met).

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar

KS86
Tera Contributor

Thank you Siva and Juhi.

You both cleared my doubts.

Chaitanya ILCR
Kilo Patron

Hi @KS86 ,

attaching the picture 

refer this, it should give you good idea on this

 

https://www.servicenow.com/community/in-other-news/order-of-script-execution-form-submission/ba-p/25...

https://www.servicenow.com/community/developer-forum/the-order-of-execution/m-p/1972553/page/2

 

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya