Thursday, 25 April 2019

Before, After, Async and Display Business Rules with Example


 BR



A business rule is JavaScript code which run when a record is displayed, inserted, updated, or deleted, or when a table is queried. Follow these guidelines to ensure that business rules work efficiently and to prevent unpredictable results and performance issues.

The When field on the business rule form indicates whether the business rule script runs before or after the current object is saved to the database. The most commonly used business rules are before and after rules. 
You can use an async business rule in place of an after business rule. Async business rules are similar to after rules in that they run after the database commits a change. Unlike after rules, async rules run in the background simultaneously with other processes. Async business rules allow ServiceNow to return control to the user sooner but may take longer to update related objects. 

Before

First, I need to check that you not posting any offensive materials. I can have a before rule to check that. According to the rules setup by me, either allow or disallow the posting of the question (Transaction).

After

Second, after you have passed the rules of posting and posted the question successfully. Someone opens up your question and likes your question. I need to award you points once the like is successful. I can have a after business rule to set this up.

Before

Third, you will need to get email trigger when someone comments on your question. It does not need to be immediate. I can have a async rule to trigger the email.

Display

Finally, I need to update the number of views of your question. I can have a display business rule to update the counter related to your question ..

No comments:

Post a comment