Client scripts & Ui policies

dellyou088
Tera Contributor

I was testing behaviour of client script and ui policies, where field A was there on which i configured a client script which does make that field readOnly and a UI policy which makes that field mandatory,

Form behaviour was such that, the field became mandatory if field is empty and it became readOnly when field was filled by any data.

1 ACCEPTED SOLUTION

PoonkodiS
Giga Sage

@dellyou088 

UI Policies override Client Scripts: UI Policies always execute last and win any conflict.

Mandatory wins over Read-Only: ServiceNow never allows a field to be both. It prioritizes mandatory so users can still enter data.

The Result

When Empty: The UI Policy forced the field to be mandatory, overriding the Client Script's read-only rule.

When Filled: The UI Policy stopped acting, allowing the Client Script to successfully make the field read-only.

Best Practice

Delete the Client Script and use one UI Policy with the condition Field A is not empty to handle both states automatically.

View solution in original post

3 REPLIES 3

Tanushree Maiti
Tera Patron

Hi @dellyou088 

 

First I will suggest you to go through script courses or videos where you will get good idea of Client script , UI policy , when we use them

Refer:

Client Script vs UI Policy: What Happens When Conditions Conflict in ServiceNow

https://www.youtube.com/watch?v=Poo_yqfRZYg

https://www.youtube.com/watch?v=K08lYNeq83k

 

Secondly , At same time a field can not be mandatory and read only.

 

Lastly , When a form loads or changes, ServiceNow executes client-side configurations in a specific sequential order:

  1. Client Scripts (including onLoad and onChange) run first.
  2. UI Policies run second, which means they execute after Client Scripts

Because UI Policies run last, they get the final say and will overwrite any conflicting configurations previously set by a Client Script.

 

Second thing is that 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
"Client Script and UI Policy" are the areas in ServiceNow where we write the "Client(Browser) Side Logic". It will be good to know under which Conditions we can use "Client Scripts or UI Policies in ServiceNow". There are only some Technical "Difference between Client Script and UI Policy" ...
For More Information, please check details below: Documentation for Catalog UI Policies - https://docs.servicenow.com/en-US/bundle/tokyo-servicenow-platform/page/product/service-catalog-management/concept/c_ServiceCatalogUIPolicy.html Documentation for Catalog Client Scripts - ...

PoonkodiS
Giga Sage

@dellyou088 

UI Policies override Client Scripts: UI Policies always execute last and win any conflict.

Mandatory wins over Read-Only: ServiceNow never allows a field to be both. It prioritizes mandatory so users can still enter data.

The Result

When Empty: The UI Policy forced the field to be mandatory, overriding the Client Script's read-only rule.

When Filled: The UI Policy stopped acting, allowing the Client Script to successfully make the field read-only.

Best Practice

Delete the Client Script and use one UI Policy with the condition Field A is not empty to handle both states automatically.

PoonkodiS
Giga Sage

@dellyou088 

Condition - field A is not empty

Reverse if false - check the checkbox

Read only - true

Mandatory - false

If the condition is not met( field A is empty)

Read only - false

Mandatory - true