The Now Platform® Washington DC release is live. Watch now!
on 05-18-2021 08:15 PM
Business Rule:- 1. A business rule is a server-side script that runs when a record is displayed, inserted, updated, or deleted, or when a table is queried.
2.Table of business rule:- sys_script .
Four type of business rule.
Database Operation :
Two steps of business rule
Before Business Rule :
Before Business Rule execute before data save into the database or table.
Step Of Execution :
Record get Save into Database or Table |
Before Business Rule will get Execute |
When user click save or update record |
When to run select before and action is insert or update.
(function executeRule(current, previous /*null when async*/)
if('current.state'!='previous.state')
{
current.impact=’1’;
current.update();
}
})(current, previous);
After Business Rule :-
After Business Rule Execute after the action perform on database or table.Whent data saved into database then after business rule Run.
Step Of Execution :
When user click save or update the record |
Record get save into database or table |
After Business Rule Script Will get Execute |
select table problem and apply after business rule perform action insert and update
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('incident');
gr.addActiveQuery(); //Cross check only active incidents
gr.addQuery('problem_id', current.sys_id);
gr.query();
while (gr.next()) {
gr.state='3';
gr.hold_reason='1';
gr.update();
}
})(current, previous);
Async Business Rule :-
Async Business Rule Execute after the action perform on database or table.Whent data saved into database then Async business rule Run. Async Business Rule task are independent to each other.They are run simultaneouly reduce the redandency.
Step Of Execution :
When user click save and update the record
|
Record get save into database or table |
|
(function executeRule(current, previous /*null when async*/) {
var value = current.u_company
// Add your code here
var gr = new GlideRecord('u_gliderecord');
gr.initialize();
gr.u_company= value;
gr.insert();
})(current, previous);
Display Business Rule :-
1.display business rule provide client script access from server side data.
Example :-Populate the caller email id if incident has any attachment.
Display Business Rule
(function executeRule(current, previous /*null when async*/) {
g_scratchpad.hasAttachments = current.hasAttachments();
g_scratchpad.email=current.caller_id.email.getDisplayValue();
})(current, previous);
Client Script
function onLoad() {
var email=g_scratchpad.email;
if(g_scratchpad.hasAttachments){
alert("Caller Email name==="+email);
}
}
Two Parameter :
1)current : current referenced current value of the Form .If we want to access current value using current parameter.
2)Previous :Previous referenced previous value of the table. If we want to access any old value using previous parameter.
Query Business Rule :Query business rule alternative way of ACl in query business it gives limited access to particular user.
Example :prevents users from accessing incident records unless they have the itil role, or are listed in the Caller or Opened by field. So, for example, when self-service users open a list of incidents, they can only see the incidents they submitted
.if(!gs.hasRole("itil") && gs.isInteractive()) {
var u = gs.getUserID();
var qc = current.addQuery("caller_id",u).addOrCondition("opened_by",u).addOrCondition("watch_list","CONTAINS",u);
gs.print("query restricted to user: " + u);
}
Please Mark it Helpful & Book Mark It
Thanks ,
Mayuri Mandavkar
WARNING!
Every year we see multiple customer escalations for performance because of poorly written before/query business rules.
The example given in this article, for example, is not a scalable solution. It is bad practice to use multiple OR conditions or CONTAINS queries in commonly executed scripts.
If you decide to use before/query business rules as an alternative to ACL's please read the following article carefully!
Performance Best Practice for Before Query Business Rules
Please ✅ Correct if this solves your issue and/or 👍 if Helpful
"Simplicity does not precede complexity, but follows it"
What is the main purpose of query business rule?
The primary purpose of a business rule is to perform a predefined set of actions that need to be performed when a record is displayed, inserted, updated, or deleted or when a table is queried. It can be achieved by any of below four types of BR's:
1) before business rule.
2) after business rule.
3) async business rule.
4) display business rule.
Thank goodness! I was looking for a business rule for myself to kick-start an online business. The business is going to assist students who want UK Assignment Help. I hope my business goes well and it could help a lot of students. This was really helpful I love it.