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

Nice, Thank you 

Yash Agrawal1
Tera Guru

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.

Sagar Pagar
Tera Patron

Check the attachment pdf

The world works with ServiceNow

Vishal Ingle4
Tera Contributor

hi 

ui policy can be used to make fileds on form visible, readonly, manadtory or clear some field values.

 

while, client script can be used to perform some complex logic with the above functionallity.

Runjay Patel
Giga Sage

Check out this video, it will clear all your doubts and help you to understand Client Script queries in details.

Link: https://www.youtube.com/watch?v=Wj8ZAWtTBqo&ab_channel=ServiceNowHelpdesk

It help you to understand below points.

  • UI policy and Client script
  • why client script run first in service now?.
  • Which rule execute first client Scripts or UI polices?
  • g_user and g_form tips
  • Difference between client script and script include (server).
  • Scenario based implementation
  • Understanding below
    • onLoad()
    • onChange()
    • onSubmit()
    • onCellEdit()

 

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