What is the difference b/w client script and data policy ??

harshshree7
Tera Contributor

What is the difference b/w client script and data policy ??

1 ACCEPTED SOLUTION

J Siva
Tera Sage

Hi @harshshree7 
Basic difference:

FeatureClient ScriptData Policy
Execution ContextClient-side (browser)Server-side (and optionally client-side)
Use CaseUI behavior and interactivityData validation and integrity
Applies ToForms and Service PortalForms, APIs, and background processes
Scripting RequiredYesNo (uses conditions and actions)

 

For more info, please chcek out th below docs.

Client scripts

Data policy

 

Regards,
Siva

View solution in original post

4 REPLIES 4

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @harshshree7 

 

https://developer.servicenow.com/dev.do#!/learn/courses/xanadu/app_store_learnv2_scripting_xanadu_sc...

 

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

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************
Part 24. Key Differences between UI Policy and Client Script: UI Policies: Ideal for simpler form behavior adjustments (visibility, mandatory fields, read-only states) without needing JavaScript. Client Scripts: More powerful and flexible, but they require JavaScript knowledge, and are suitable ...

Arun_Manoj
Mega Sage

Hi @harshshree7 ,

 

 

Aspect Details : Client Script

Runs onClient side (browser)
PurposeControls form behavior: hide/show, read-only, validation, auto-fill
Used InForms (UI), Service Portal, Catalog
TypesonLoad, onChange, onSubmit, onCellEdit
ScopeOnly affects the user interface — does not apply to data imported via scripts or integrations
ExampleMake a field read-only when the state is "Closed" on form load

 

Aspect Details : Data Policy

Runs onServer side, but can enforce rules on both UI and data API
PurposeEnforce data integrity by making fields mandatory or read-only
Used InAny record update: form, script, import set, integration
ScopeApplies to data regardless of how it's entered (UI, API, imports)
ExampleAlways require "Category" field on Incident, even during an import or Flow execution

 

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,

Arun Manoj

J Siva
Tera Sage

Hi @harshshree7 
Basic difference:

FeatureClient ScriptData Policy
Execution ContextClient-side (browser)Server-side (and optionally client-side)
Use CaseUI behavior and interactivityData validation and integrity
Applies ToForms and Service PortalForms, APIs, and background processes
Scripting RequiredYesNo (uses conditions and actions)

 

For more info, please chcek out th below docs.

Client scripts

Data policy

 

Regards,
Siva

Ehab Pilloor
Mega Sage

Hi @harshshree7,

 

Data Policies

Data policies enable you to enforce data consistency by setting mandatory and read-only states for fields.

Data policies are similar to UI policies, but UI policies only apply to data entered on a form through the standard browser. Data policies can apply rules to all data entered into the system, including data brought in through import sets or web services and data entered through the mobile UI.

For example, suppose that you are configuring a web service that allows users from outside the platform to update problems on the ServiceNow instance. Since these problems are not updated through the instance UI, they are not subject to the UI policies on the problem form. To ensure that the Close notes field is completed before a problem is marked Closed/Resolved, you can create a data policy that applies to server-side imports. Data that does not comply with this data policy produces an error. You can also apply the policy on the browser by selecting the Use as UI Policy on client check box in the data policy record.

Since UI policies can also manage the visibility of fields on a form, you may want to augment UI policies with data policies rather than replace them.

By default, data policies are applied to all GlideRecord operations including those used in Scripted REST APIs, and the REST Table API. You can opt out of applying the data policy to:
  • Target records of SOAP web services
  • Import sets
  • Client-side UI policies

The admin role is required to edit data policies.

Note: Defining a data policy enforces the policy when a record is submitted from the UI. This behavior cannot be changed.
 
Client Scripts

Client scripts allow the system to run JavaScript on the client (web browser) when client-based events occur, such as when a form loads, after form submission, or when a field changes value.

 

Use client scripts to configure forms, form fields, and field values while the user is using the form. Client scripts can:

  • make fields hidden or visible
  • make fields read only or writable
  • make fields optional or mandatory based on the user's role
  • set the value in one field based on the value in other fields
  • modify the options in a choice list based on a user's role
  • display messages based on a value in a field

 

 

Sources used: https://www.servicenow.com/docs/bundle/yokohama-api-reference/page/script/client-scripts/concept/cli...

https://www.servicenow.com/docs/bundle/yokohama-platform-administration/page/administer/field-admini...

 

 

Regards,

Ehab Pilloor