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

please close this thread, then only this will be helpful to others....




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

Shubha_Prada
Tera Guru

Hi @sas11 ,

 

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:- 

Criteria Client Script UI 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 Product Documentation for more details -

Client Scripts vs. UI Policies | ServiceNow Developers

 

 

  • Additionally, you can use Client scripts for UI policies.

Any scripts you create for UI policies run on the client side.

You can use different options in the UI Policy form to control when and how the UI policy is applied. These options include client scripts, OnLoad execution, and view-specific UI policies. Administrators can use the UI Policy form to create client scripts that run onChange when the UI policy conditions are met (Execute if true) or not met (Execute if false).To display these scripting fields in the UI Policy form, in the Script section, select the Run scripts check box.

For example, to display an alert to the user when the incident State field changes to Resolved, create the following script in the Execute if true field.
function onCondition(){
alert('You changed the "Incident state" to Resolved. Please enter your comments in the "Close notes" field.');
}
 

Service catalog UI policies control the behavior of catalog item forms. Service catalog UI policies can be applied to a catalog item or a variable set. For more information about using UI policies for service catalog items, see Service catalog UI policy

 

 

Please mark this solution as helpful if it helps you.

 

Regards,

Shubha S