Difference between client script and ui policy

Mr_Blue
Tera Expert

Hello All,

I am new to ServiceNow, I am studying UI Policy and Client Scripts.

I know they both runs on Client side, Can some one please give me a real life use case scenarios, Ex : [ where to use what ]

If possible, can you please provide me multiple use case scenarios.....

 

i was following this article :: 

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

 

Thank You...

1 ACCEPTED SOLUTION

Harsh Vardhan
Giga Patron

Real Time Scenario : 

 

UI Policy : if you want to make your form field "Mandatory" "Read Only" "Visible" based on some field condition or browser load then you can simply use UI Policy here.

 

Let's take an example : i want to make work notes field mandatory based on the state field value. so this is a simple straight forward requirement. so here i will go with UI Policy. 

i will Create an UI Policy and set the filter condition State | IS | Resolved then in the UI Policy action i will set true for Work notes field. 

 

If you have a similar requirement but the work notes field should be mandatory on form Submission then you have to use here onSubmit Client script because in UI Policy you can either set it on field change or form load ( only in these two scenario you can run the UI Policy ).

But Client script can be run on either onLoad() , onChange() , onSubmit() or onCellEdit().

 

Now Coming to the Client SCript: 

if you have a scenario here , to populate some field value in short description field.  example:

I want to set CAller title in to the short description then here you can write onChange() client script on caller field to get the caller title value and set into the short description field. 

Now you compare the first example and the second example, you will see the complexity in the requirement. 

this way you can decide on which scenario you should use UI Policy and Client Script.

 

I am adding one TechNow Episode here .  this is specific to the client script.

 

TechNow Episode 5 | Client-Side Scripting Fundamentals

 

 

View solution in original post

14 REPLIES 14

Harsh Vardhan
Giga Patron

adding one blog link here. 

kindly have a look. 

 

A Race between UI Policy and Client script

Priyanka Pednek
Kilo Guru

 Hi 

 

Client script:Client scripts are shipped to the client (the browser) and run there instead of on the server. Users who know JavaScript can define scripts to run in the client browser

UI policy:UI policies offer an alternative to client scripts for dynamically changing information on a form. Administrators and users with the Personalize Rules [personalize_rules] or the UI policy administrator [ui_policy_admin] role can use UI policies to define custom process flows for tasks.

 

 NOTE:As a best practice always use UI policy if you want to make field to be hidden,readonly,Mandatory

You can go with UI policy incase of onLoad and onChange and you can also use the script based on true and false conditions.

 

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

 

Your understanding is correct regarding the client script.

 

Please go through the below link to know what is the difference among script

 

1) http://wiki.servicenow.com/index.php?title=Differences_Among_Scripts

 

2) http://jamesn903.files.wordpress.com/2014/04/15lb3-scripting201.pdf   --> Some pages of this would be helpful.

 

3) Wizard UI Policy and Client Scripts - ServiceNow Wiki

 

https://community.servicenow.com/community?id=community_question&sys_id=fe65b869dbe0dbc03882fb651f96...

https://community.servicenow.com/community?id=community_question&sys_id=53b70be9db1cdbc01dcaf3231f961916

https://community.servicenow.com/community?id=community_blog&sys_id=512d26e5dbd0dbc01dcaf3231f9619ce

 

Please mark reply as Helpful/Correct, if applicable. Thanks!

 

Harsh Vardhan
Giga Patron

Real Time Scenario : 

 

UI Policy : if you want to make your form field "Mandatory" "Read Only" "Visible" based on some field condition or browser load then you can simply use UI Policy here.

 

Let's take an example : i want to make work notes field mandatory based on the state field value. so this is a simple straight forward requirement. so here i will go with UI Policy. 

i will Create an UI Policy and set the filter condition State | IS | Resolved then in the UI Policy action i will set true for Work notes field. 

 

If you have a similar requirement but the work notes field should be mandatory on form Submission then you have to use here onSubmit Client script because in UI Policy you can either set it on field change or form load ( only in these two scenario you can run the UI Policy ).

But Client script can be run on either onLoad() , onChange() , onSubmit() or onCellEdit().

 

Now Coming to the Client SCript: 

if you have a scenario here , to populate some field value in short description field.  example:

I want to set CAller title in to the short description then here you can write onChange() client script on caller field to get the caller title value and set into the short description field. 

Now you compare the first example and the second example, you will see the complexity in the requirement. 

this way you can decide on which scenario you should use UI Policy and Client Script.

 

I am adding one TechNow Episode here .  this is specific to the client script.

 

TechNow Episode 5 | Client-Side Scripting Fundamentals