Вы находитесь на странице: 1из 5

Business Rules

1
Business Rules
Overview
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. Use business rules to accomplish tasks like automatically changing values in form fields when
certain conditions are met, or to create events for email notifications and script actions.
Note: Business rules can make use of scripts to take actions on records in the database. However, there are several other scripting
options available on the ServiceNow platform, such as client scripts and UI actions. See Differences Among Scripts to understand
which scripting option is best for the actions you want to take.
How Business Rules Work
To configure business rules, you first need to determine when the business rule should run and what action it should
take.
When Business Rules Run
Business rules run based on two sets of criteria:
The time that the business rule is configured to run relative to a record being modified or accessed.
The database operation that the system takes on the record.
The following options are provided to determine the time the business rule should run:
Option When the Rule Runs
Before After the user submits the form but before any action is taken on the record in the database.
After After the user submits the form and after any action is taken on the record in the database.
Async When the scheduler runs the rule. The rule is put into the scheduler's queue after the user submits the form and after any action is taken on
the record in the database.
Display Before the form is presented to the user, just after the data is read from the database.
Note: Asynchronous business rules do not have access to the previous version of a record. Therefore, these GlideElement methods do
not work with async rules: changes(), changesTo(), changesFrom().
The following options are provided to determine the database operation that the system takes on the record:
Business Rules
2
Option When the Rule Runs
Insert When the user creates a new record and the system inserts it into the database.
Update When the user modifies an existing record.
Query Before a query for a record or list of records is sent to the database. Typically you should use query for before business rules. See
Before-Query example.
Delete When the user deletes a record.
This image shows when different types of business rules run:
Business rule processing flow
Note: Business rules apply consistently to records regardless of whether they are accessed through forms, lists, or web services. This
is one major difference between business rules and client scripts, which apply only when the form is edited.
Business Rule Actions
Business rules can perform a variety of actions. Common types of actions are:
Changing field values on a form that the user is updating. Field values can be set to specific values available for
that field, values copied from other fields, and relative values determined by the user's role.
Displaying information messages to the user.
Changing values of child tasks based on changes to parent tasks.
Preventing users from accessing or modifying certain fields on a form.
Administrators can set field values and create information messages without writing a script starting with the Eureka
release. In versions prior to Eureka, administrators must write scripts to perform the actions that business rules take.
See Creating a Business Rule for details on which options are available for your version. See Scripting in Business
Rules for script examples.
Business Rules
3
Creating a Business Rule
1. Navigate to System Definition > Business Rules.
2. Click New.
3. Fill in the fields, as appropriate (see table).
4. Click Submit.
The advanced version of the Business Rule form that closes a task before the insert or
update is written to the database.
Note: You might need to personalize the form to see all the fields below.
Field Description
Name Enter a name for the business rule.
Table Select the table that the business rule runs on.
Active Select this check box to enable the business rule.
Advanced Select this check box to see the advanced version of the form.
When to run
When [Advanced] Select when this business rule should execute: display, before, async, or after the database operation is complete.
Order [Advanced] Enter a number indicating the sequence in which this business rule should run. If there are multiple rules on a particular
activity, the rules run in the order specified here, from lowest to highest.
Insert Select this check box to execute the business rule when a record is inserted into the database.
Update Select this check box to execute the business rule when a record is updated.
Delete [Advanced] Select this check box to execute the business rule when a record is deleted from the database.
Query [Advanced] Select this check box to execute the business rule when a table is queried.
Filter
Conditions
Use the condition builder to determine when the business rule should run based on the field values in the selected Table (starting with
the Eureka release). You can also use the Condition field to build a condition with a script.
Role
Conditions
Select the roles that users who are modifying records in the table must have for this business rule to run.
Actions
Business Rules
4
Set field
values
Set values for fields in the selected Table using the choice lists (starting with the Eureka release):
The field.
The assignment operator:
To: An exact value.
Same as: The value of another field.
To (dynamic): A value relative to the user configuring the business rule or a user with a specific role.
The value.
Add
message
Select this check box and enter a message that appears when this business rule is run (starting with the Eureka release).
Abort
action
Select this check box to hide the Set field values and Script fields (starting with the Eureka release). You can still display a message
to users by selecting the Add message check box and composing the message.
Advanced
Condition [Advanced] Create a JavaScript conditional statement to specify when the business rule should run. By adding the condition statement
to this field, you tell the system to evaluate the condition separately and run the business rule only if the condition is true. If you
decide to include the condition statement in the Script field or if you use the condition builder, leave this field blank. To have the
instance reevaluate the condition statement a second time before running an async business rule, add the system property
glide.businessrule.async_condition_check and set the value to true. See business rules best practices for an example
of how to use this field.
Script [Advanced] Create a script that runs when the defined condition is true. For more information and examples, see Scripting in Business
Rules.
Related list: Versions
Versions Shows all versions of the business rule. Use this list to compare versions or to revert to a previous version. For more information, see
Versions.
Enhancements
Eureka
Administrators can accomplish these tasks without writing a script:
Build conditions using the condition builder.
Set field values on the form specified in the rule. A set of choice lists allows administrators to set a field to a
specific value, the value in another field, or a dynamic value based on the user.
Display an alert message. Administrators can use an HTML text field to compose a message
The Business Rule form provides two versions:
A default version that provides a simplified form. On this version, administrators can create insert business
rules or update business rules that run before a database change is made.
An advanced version that provides additional options. On this version, administrators can create any type of
business rule and determine when the rule runs.
Article Sources and Contributors
5
Article Sources and Contributors
Business Rules Source: http://wiki.servicenow.com/index.php?title=Business_Rules Contributors: CapaJC, Cheryl.dolan, Doug.penta, Emily.partridge, G.yedwab, George.rawlins, Guy.yedwab,
John.andersen, John.roberts, Joseph.messerschmidt, Michelle.Corona, Neola, Phillip.salzman, Rachel.sienko, Steven.wood, Suzanne.smith, Vaughn.romero
Image Sources, Licenses and Contributors
Image:Warning.gif Source: http://wiki.servicenow.com/index.php?title=File:Warning.gif License: unknown Contributors: CapaJC
Image:Business_rules_flow.jpg Source: http://wiki.servicenow.com/index.php?title=File:Business_rules_flow.jpg License: unknown Contributors: John.roberts
Image:Business_Rule_Eureka.png Source: http://wiki.servicenow.com/index.php?title=File:Business_Rule_Eureka.png License: unknown Contributors: Maintenance script, Phillip.salzman