You are on page 1of 3

Business Rules

This introduction explains how business rules work and their benefits over other
types of coding components.
All business rules have the following characteristics:
When to Run:
o When: type that determines when they run in relation to database
operations (e.g. Before, after, async and display)
o A list of database operations that can trigger them (e.g. Insert, Update,
Delete, and Query)
Action: This tab can do one or more of the following
o Set one or more field values
o Display a message
o Abort the current database operation
Advance: Run custom code
Developers typically use custom code in business rules to:
Perform database operations, such as querying for a list of records
Check for complex conditions
Check for dynamic values
Display information to the user, such as validation errors
Change field values, such as changing the incident state from resolved to
closed
Use a

business rule when you want to:


Run a business logic that involves a database related operation.
Automate business logic rather than require manual user interaction.
Ensure business logic runs no matter what its source. For example, when:
o A user submits a form
o A web service requests a database operation

Type
Before

After

Async

Runs
After the user submits the
form but before the record
is inserted/updated in the
database.
After the user submits the
form and after the system
takes action on the record
on the database.
As an asynchronous
scheduled job in the

Use to
Validate data before
inserting or updating into
the database.
Perform calculations or
business logic on data,
such as updating totals or
counts.
Perform calculations or
business logic on data in

Display

background after the user


submits the form and after
the system takes action
on the record on the
database.
Before the system
displays the form to the
user and just after the
system reads a record
from the database.

the background. Allows


the system to do other
tasks, such as loading a
form or running other
business rules.
Perform calculations or
business logic on data
that may affect user input,
such as the current price
of a catalog item.

Create a before business rule


In this exercise you create a before business rule to validate the marketing event
budget whenever a user inserts or updates a record. You want to abort any insert or
update where the marketing event budget is zero.
A before business rule is a good fit for this business logic because the system can
validate all inserts and updates to the target table regardless of the input method.
Validation occurs whether a user submits a form, a user submits a service catalog
record producer request, or there is an automated web services request.
Navigate to System Definition > Business Rules.
Click New.
Enter the following field values.
Field
Value
Name
Validate marketing event
Table
Marketing Event
Advanced
Selected
When
Before
Insert
Selected
Update
Selected
Script
function onBefore(current, previous) {
//This function will be automatically
called when this rule is processed.
var checkbudget =
current.budget.getCurrencyValue();
if(checkbudget < 1){
gs.addErrorMessage('Budget must
be greater than zero');
current.setAbortAction(true);
}

Click Submit.

You might also like