difference between client script and ui policy

sas11
Kilo Contributor

difference between client script and ui policy

6 REPLIES 6

Rajesh Mushke
Mega Sage
Mega Sage

Hi Sasmita,



you can find everything in this blog post.



A Race between UI Policy and Client script




Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke

Jaspal Singh
Mega Patron
Mega Patron

Hi Sasmita,



Apart from what Rajesh has suggested in post above. In simple terms, both UI Policy & Client Script are almost similar only thing is scripting is involved in Client script, also client scripts excutes first when compared to UI Policies.


Rajesh Mushke
Mega Sage
Mega Sage

now i will explain best practices,



UI Policy :



1. ui policies are alternate to client scripts.


2. Always use Ui policy for making fields read-only and Mandatory & Hiding.



Client Scripts vs. UI Policies


Client Scripts and UI Policies both execute client-side logic and use the same API. Both are used to manage forms and their fields. When developing an application, how can you decide which client-side script type to use? Use this table to determine which type is best suited to your application's needs:


CriteriaClient ScriptUI Policy
Execute on form loadYesYes
Execute on form save/submit/updateYesNo
Execute on form field value changeYesYes
Have access to field's old valueYesNo
Execute after Client ScriptsNoYes
Set field attributes with no scriptingNoYes
Require control over order of execution*YesYes


*Although the Order field is not on the Client Script form baseline you can customize the form to add it.


UI Policies execute after Client Scripts. If there is conflicting logic between a Client Script and a UI Policy, the UI Policy logic applies.



Refer :


https://developer.servicenow.com/app.do#!/training/article/app_store_learnv2_scripting_jakarta_clien...




Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke

Rajesh Mushke
Mega Sage
Mega Sage

Hello Sasmita,



Hope your query is been answered , so please close this thread.




Then only this will be helpful for other community customers.



Let me know if that answered your question. If so, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list. Visit How To Mark Answers Correct From Community Inbox



Thanks in Advance............




Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke