client script vs ui policies vs business rules

1__SathvikT
Tera Contributor

I have a task please help me out to do it.

Task : when the order type changes to product then the priority field value has to set for high

 

For doing this task which is better to use either client script or business rules or ui policies and ui action?Why?

Then how to do this? Give me complete step of actions.

3 ACCEPTED SOLUTIONS

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @1__SathvikT 

 

You can use the look up table as well, or via client script. reason, we want to make changes before going in DB.

*************************************************************************************************************
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]

****************************************************************************************************************

View solution in original post

Deepak Shaerma
Kilo Sage

Hi @1__SathvikT 

For modifying field values based on changes to other fields on the server-side, using a Business Rule is the most appropriate approach. 
Steps to Create a Business Rule:

1. Navigate to System Definition: Go to  System Definition & Business Rules in the navigator/search bar.

2. New Business Rule: Click on the New button to create a new Business Rule.

3. Fill in Basic Information:
Name
Table: Select the table 
Advanced: Check this box,

4. When to Run:
- In the When to run tab, configure the rule to run After an insert or update. This is because you want to check the value after it has been changed or set.
Conditions: Set the condition to run your Business Rule. For example:
- Field: Order Type
- Operator: changes to
- Value: product
- This means your script will execute when the order type is set or changes to “product”.

if (current.order_type == 'product') {
    current.priority = '1';
}



Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help us a lot.
- Keep Learning ‌‌
Thanks & Regards 
Deepak Sharma

View solution in original post

Sandeep Rajput
Tera Patron
Tera Patron

@1__SathvikT Ideally this should be handled at the client side via the UI Policy. It is the best and most performant way. Client script slows the form rendering and browser a bit and business rules on the other side makes an instance execute some extra steps when ever a record is created/updated/deleted which is again should be done when absolutely necessary. In your case, neither of two (client script and business rule) is needed.

 

Hope this helps.

View solution in original post

4 REPLIES 4

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @1__SathvikT 

 

You can use the look up table as well, or via client script. reason, we want to make changes before going in DB.

*************************************************************************************************************
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]

****************************************************************************************************************

Deepak Shaerma
Kilo Sage

Hi @1__SathvikT 

For modifying field values based on changes to other fields on the server-side, using a Business Rule is the most appropriate approach. 
Steps to Create a Business Rule:

1. Navigate to System Definition: Go to  System Definition & Business Rules in the navigator/search bar.

2. New Business Rule: Click on the New button to create a new Business Rule.

3. Fill in Basic Information:
Name
Table: Select the table 
Advanced: Check this box,

4. When to Run:
- In the When to run tab, configure the rule to run After an insert or update. This is because you want to check the value after it has been changed or set.
Conditions: Set the condition to run your Business Rule. For example:
- Field: Order Type
- Operator: changes to
- Value: product
- This means your script will execute when the order type is set or changes to “product”.

if (current.order_type == 'product') {
    current.priority = '1';
}



Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help us a lot.
- Keep Learning ‌‌
Thanks & Regards 
Deepak Sharma

Sandeep Rajput
Tera Patron
Tera Patron

@1__SathvikT Ideally this should be handled at the client side via the UI Policy. It is the best and most performant way. Client script slows the form rendering and browser a bit and business rules on the other side makes an instance execute some extra steps when ever a record is created/updated/deleted which is again should be done when absolutely necessary. In your case, neither of two (client script and business rule) is needed.

 

Hope this helps.

swathisarang98
Giga Sage
Giga Sage

Hi @1__SathvikT ,

 

you can go ahead with client script or business rule,

 

If you choose client script - create onchange client script and filed give as order type

 

in script 

 

 

var order = g_form.getValue('order_type'); //write the backend name of order type

if(order == "product"){ //write the backend name of product
g_form.setValue('priority','1'); //give the backend name and value
}

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang