We can call business rules in Client Scripts, if we call BR Please tell me which scenarios we can Call?

ram2497
Tera Contributor

We can call business rules in Client Scripts, if we call  BR Please tell me which scenarios we can Call?

Please provide any examples.

Note: We Can Call Client Scripts in Business Rules.(Please provide any examples, If Yes)

Thanks

Ram

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@ram2497 

Basically both are different.

There are not many actual real-time scenarios wherein you required calling business rule from client script

and is not recommended best practice.

Client Script - they run when form is loaded and run on UI i.e. frontend

Business Rule - they run when form is submitted i.e. any database transaction happens such as insert/update/delete and is server side

Please find the below responses:

1) Call Client Script in Business Rule - not possible

2) Call business rule from Client Script - Use Script includes instead of global business rules

Do not create a business rule, but instead navigate to System Definition > Script Include and create a new script

Advantage of using Script Include over Global Business rule:

1) You can have re-usable function which can be called from multiple server side scripts such as workflow run script, other business rule, other script include, schedule job etc

Use Script Includes Instead of Global Business Rules

Regards
Ankur

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

View solution in original post

4 REPLIES 4

MrMuhammad
Giga Sage

You need to create Global Business rule and the you can call it anywhere but that is not recommended and have adverse effects. Instead we use script includes to process server side data and call it from Client script using GlideAjax. 

Please refer  

Glide AJAX DOCS  

https://docs.servicenow.com/bundle/orlando-application-development/page/script/ajax/topic/p_AJAX.htm...

Use Script Includes Instead of Global Business Rules

https://developer.servicenow.com/app.do?_escaped_fragment_=/document/content/app_store_doc_technical...

 

Thanks & Regards,

Sharjeel

Regards,
Muhammad

Ankur Bawiskar
Tera Patron
Tera Patron

@ram2497 

Basically both are different.

There are not many actual real-time scenarios wherein you required calling business rule from client script

and is not recommended best practice.

Client Script - they run when form is loaded and run on UI i.e. frontend

Business Rule - they run when form is submitted i.e. any database transaction happens such as insert/update/delete and is server side

Please find the below responses:

1) Call Client Script in Business Rule - not possible

2) Call business rule from Client Script - Use Script includes instead of global business rules

Do not create a business rule, but instead navigate to System Definition > Script Include and create a new script

Advantage of using Script Include over Global Business rule:

1) You can have re-usable function which can be called from multiple server side scripts such as workflow run script, other business rule, other script include, schedule job etc

Use Script Includes Instead of Global Business Rules

Regards
Ankur

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

RAHUL Khanna1
Mega Guru

Just to Add on to above answers, 

1) we do have a field called "Client Callable" still on the BR from, and if you filter the BR records you can find many BR's with this box checked.

2) These are the server scripts, that run on Global table, and in olden days where there was a no concept of Script Include, developers use to create a BR on global table and make a ajax call to call this script: 

 

Runjay Patel
Giga Sage

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

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

It help you to understand below points.

  • Scenario based business rule uses
  • Best business use cases for all types of business rules
  • Current .update in before business rule
  • Difference between Before BR and Before query BR?
  • Where can we use query business rule?
  • All type of business rule with real world scenario
    • Before
    • After
    • Async
    • Display

 

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