what are the benefits of ui policy over client script or vice versa?which one is more beneficial?please explain in simple ways because i m kinda new to servicenow

kshitij4
Giga Contributor

what are the benefits of ui policy over client script or vice versa?which one is more beneficial?please explain in simple ways because i m kinda new to servicenow..

thanks in advance for ur advice!!!!!!!!!!!

1 ACCEPTED SOLUTION

Hussain Kachwal
Mega Guru

Hello Kshitij,

Request to you follow the below blog:


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

 


Kindly mark as Answered or Helpful, if applicable.


-Hussain K

View solution in original post

3 REPLIES 3

Hussain Kachwal
Mega Guru

Hello Kshitij,

Request to you follow the below blog:


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

 


Kindly mark as Answered or Helpful, if applicable.


-Hussain K

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Kshitij,

Both the scripts are client side and have their own importance in terms of usage.

UI Policies are mostly used when you just want to make field mandatory, visible, readonly on simple condition such as state=closed

Client scripts are mostly used when you want to make field mandatory, visible ,readonly on complex conditions such as if user has role and state is closed then do something.

Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Nirupam Biswas
ServiceNow Employee
ServiceNow Employee

Client Scripts are powerful because they require that you write codes. If possible always use UI Policies as they allow you accomplish many complicated tasks without any codes. I will provide two scenarios which would help to drive home the point.

Scenario 1

On Incident form if state is On Hold then only On Hold Reason field should appear.

Using UI Policy all you need to do is create a policy where State = On Hold. Then in Action related list you need to add the On Hold Reason field and set its Visible option to true. By default UI Policies have a "Reverse if false" checkbox checked. That means when State is not On Hold then On Hold Reason field is made invisible.

Using Client Script, first you need to write code which would trigger onChange of State field. There you will need to ensure that you do not forget to write code to hide the field when state is not On Hold.

Scenario 2

On Incident form if state is 'On Hold' and 'On Hold Reason' is 'Awaiting Caller' then Additional Comments should be mandatory.

Using Client Script this would be very difficult since you will need to write two client scripts. One for onChange of State and another for onChange of On Hold Reason.

Using UI Policy it is a no brainer. When you check for complex conditions then UI Policies much powerful. In fact that is why Advanced mode Ui Policies allow you to write scripts. In such cases, even if you have to write scripts, then writing them in UI Policies is easier than handling the same scenario via Client Scripts.

 

You write Client Scripts  when you can't handle that via UI Policies.