Skip to content
✦ Made with Docsie · generated from video

How to Create a Business Rule in ServiceNow

This guide walks you through how to create a business rule in ServiceNow, specifically a "before" business rule that runs before a record is saved to the database. You'll learn how to configure the rule, write scripting logic to automatically set field values, and add validation that aborts an update when a field value doesn't meet your criteria.

ServiceNow 38 steps 28 screenshots 2134 words Source video 11:11 Generated cost $4.20

Video: ServiceNow Before Business Rule Training Videos | Before Business Rule in ServiceNow with Examples by Basico ServiceNow Learning (2019). All credit for the demonstration goes to the creator; watch the original on YouTube. The written guide below was generated from this video by Docsie. Creator? Request a change or removal.

This guide walks you through how to create a business rule in ServiceNow, specifically a "before" business rule that runs before a record is saved to the database. You'll learn how to configure the rule, write scripting logic to automatically set field values, and add validation that aborts an update when a field value doesn't meet your criteria.

Prerequisites

  • Access to a ServiceNow Personal Developer Instance.
  • Login credentials with System Administrator privileges.

Understanding before business rules

A business rule is a server-side script in ServiceNow. It runs when a record is displayed, inserted, updated, deleted, or when a table is queried.

A before business rule executes before data is saved to the database. The actions you define in the script run first, and only afterward does the form get updated or inserted. This ensures that any logic or validation you want to apply happens before the record is committed.

Slide explaining that a before business rule runs before data is saved, so specified actions execute first and the form is updated or inserted afterward
Slide explaining that a before business rule runs before data is saved, so specified actions execute first and the form is updated or inserted afterward

When a user clicks Save or Update on a record such as an incident form, the before business rule script executes first, and the record is then saved to the database or table.

1

Open your ServiceNow instance

Open your ServiceNow Personal Developer Instance. The dashboard displays navigation options on the left and a main workspace in the center, with the logged-in user shown as System Administrator. You may see a prompt to create a dashboard version of the homepage.

ServiceNow Personal Developer Instance home page showing the navigation menu, a dashboard prompt, and the user logged in as System Administrator
ServiceNow Personal Developer Instance home page showing the navigation menu, a dashboard prompt, and the user logged in as System Administrator

Create a before business rule in ServiceNow

Follow these steps to create the business rule and configure its basic settings.

Step 1: Navigate to Business Rules

In the left navigation filter, search for "business rule" and click Business Rules under the System Definition section.

ServiceNow dashboard with "business rule" entered in the left navigation filter and the Business Rules option highlighted
ServiceNow dashboard with "business rule" entered in the left navigation filter and the Business Rules option highlighted

Step 2: Open the Business Rules list

The Business Rules list displays all existing rules, with columns for Name, Active, Table, When, Application, Order, Updated, Created, Created by, and Execute function. Click the blue New button at the top left to create a new rule.

Business Rules list in ServiceNow with the New button highlighted
Business Rules list in ServiceNow with the New button highlighted

Step 3: Name the business rule

In the Name field, enter a name for your rule — for this example, demoBeforBusinessRule. Confirm that Global is selected in the Application field, that the Active checkbox is checked, and leave the Advanced checkbox unchecked for now.

Step 4: Select the target table

Click the dropdown for the Table field, type "incident" in the search box, and select Incident [incident] from the list.

Business Rule form with the Table dropdown open and Incident [incident] being selected

Step 5: Enable advanced options

Check the Advanced checkbox to enable scripting and additional configuration options. New tabs, including When to run, Actions, and Advanced, appear once this is enabled.

Business Rule form with the Advanced checkbox checked, revealing additional tabs and options
Business Rule form with the Advanced checkbox checked, revealing additional tabs and options

Step 6: Set when the rule should run

In the When dropdown, select before to specify that this is a before business rule. In the Order field, enter 100 to control the execution order relative to other rules. Leave the Insert, Update, Delete, and Query checkboxes unchecked for now.

Business Rule form with When set to before and Order set to 100
Business Rule form with When set to before and Order set to 100

Step 7: Add optional filter and role conditions

Use the Filter Conditions section to specify conditions under which the rule should run, such as only for certain field values. Click Add Filter Condition or Add 'OR' Clause as needed. In the Role conditions section, click the pencil icon to select specific roles that can trigger the rule.

Business Rule form with the Role conditions field highlighted, ready for role selection
Business Rule form with the Role conditions field highlighted, ready for role selection

Step 8: Choose the execution triggers

Review the Insert, Update, Delete, and Query checkboxes, which determine when the rule executes:

  • Insert: Runs when a new record is created.
  • Update: Runs when an existing record is modified.
  • Delete: Runs when a record is deleted.
  • Query: Runs when a record is queried.

You can select one or multiple options. For this example, select Update so the rule runs only when a record is updated.

ServiceNow Business Rule form with the Update checkbox selected under execution triggers
ServiceNow Business Rule form with the Update checkbox selected under execution triggers

Step 9: Review the Actions tab

Click the Actions tab. Here you can set field values directly using the Set field values dropdown, add messages, or configure abort actions without writing a script. This guide uses scripting instead of these direct actions.

Step 10: Open the Advanced tab for scripting

Click the Advanced tab. The Script section is pre-populated with a function template:

(function executeRule(current, previous /*null when async*/) {
    // Add your code here
})(current, previous);

You can add conditions either in the Condition field or directly within the script using if statements.

Advanced tab in the ServiceNow Business Rule form with the script editor open, ready for custom scripting
Advanced tab in the ServiceNow Business Rule form with the script editor open, ready for custom scripting

The two use cases covered in this guide are setting field values using scripting, and aborting the action by validating a field value.

Slide listing two use cases: setting field values using scripting, and aborting the action by validating the field value
Slide listing two use cases: setting field values using scripting, and aborting the action by validating the field value

Step 11: Confirm the target table

Ensure the Table field remains set to Incident [incident], so the business rule applies to the Incident table.

Business Rule form in ServiceNow with Incident [incident] selected as the target table

Write a script to set the email field automatically

These steps show how to use scripting to automatically populate a field with the current user's email address.

Step 1: Open an existing incident record

Navigate to the Incidents list and locate the incident with number INC0010680. Click the incident number to open the record.

ServiceNow Incidents list with incident INC0010680 highlighted, showing columns for Number, Caller, Short description, and other fields
ServiceNow Incidents list with incident INC0010680 highlighted, showing columns for Number, Caller, Short description, and other fields

Step 2: Review the incident record details

Confirm the record details, including Number INC0010680, Caller Bertie Luby, Category Inquiry / Help, Email record@record.com, Priority 5 - Planning, State New, and the short description. Review other fields such as Subcategory, Business service, Configuration item, Assignment group, Assigned to, Start Date, and End Date.

Step 3: Prepare to update the record

Make any necessary changes to the record's fields, such as Category or Email. Updating the record will trigger any before business rules configured for the Incident table.

Step 4: Edit the email field

Click into the email field and enter or update its value, for example record@record.com.

Cursor placed in the email field, with the value set to record@record.com
Cursor placed in the email field, with the value set to record@record.com

Step 5: Identify the email field's column name

Right-click the email field label to open the context menu and select Show - 'u_email' to reveal the column name used for scripting. The column name for the email field is u_email.

Right-click context menu on the email field label showing the Show - u_email option
Right-click context menu on the email field label showing the Show - u_email option

Step 6: Write a script to set the email field to the current user

In the Advanced tab of the business rule for the Incident table, enter code to set u_email to the current user's email. Use the code completion suggestions to select the correct method:

(function executeRule(current, previous /*null when async*/) {
    current.u_email = gs.getUser(). // continue with appropriate method
})(current, previous);

Step 7: Finalize the script

Complete the script so it sets the email field to the current user's email address:

(function executeRule(current, previous /*null when async*/) {
    current.u_email = gs.getUser().email;
})(current, previous);

Confirm that both Active and Advanced checkboxes are checked, and leave the Condition field blank unless you want to restrict when the rule runs.

Business Rule editor showing the finalized script that sets current.u_email = gs.getUser().email for the Incident table, with Active and Advanced checked
Business Rule editor showing the finalized script that sets current.u_email = gs.getUser().email for the Incident table, with Active and Advanced checked

Step 8: Name and save the business rule

Enter a name such as demoBeforBusinessRule, confirm the Table is set to Incident [incident] and Application is set to Global, then click Submit or Update to save the rule.

Step 9: Test the rule by refreshing the incident record

Return to the incident record and refresh the page to trigger the before business rule. Observe whether the email field updates to the current user's email address.

Incident record INC0010680 open, ready to be refreshed to test the business rule
Incident record INC0010680 open, ready to be refreshed to test the business rule

Step 10: Observe the email field update

After refreshing, check the email field. Its value should update to the email address of the currently logged-in user, for example record@business.com.

Incident record showing the email field updated to record@business.com after the business rule executed
Incident record showing the email field updated to record@business.com after the business rule executed

Step 11: Verify the email field value

Confirm the email field now displays the correct value, such as record@business.com. If you're logged in as a different user, the field reflects that user's email address instead.

Incident record with the email field showing record@business.com and the cursor pointing at the field
Incident record with the email field showing record@business.com and the cursor pointing at the field

Step 12: Check for further updates

Refresh again or save the record another time. The email field should continue to reflect the current user's email, for example admin@example.com if you're logged in as admin.

Incident record with the email field updated to admin@example.com after another refresh or save
Incident record with the email field updated to admin@example.com after another refresh or save

Step 13: Understand the rule's flexibility

The business rule sets the email field to the current user's email regardless of its previous value, whether blank or otherwise. This ensures consistent, automated population of the email field on incident records.

Incident record with the email field showing admin@example.com, confirming the rule works for any prior value
Incident record with the email field showing admin@example.com, confirming the rule works for any prior value

Validate field values and abort invalid actions

This section shows how to use a business rule to validate a field's value and abort the record action if validation fails, while displaying informational messages based on the outcome.

Step 1: Review the incident record for validation

Open the incident record (INC0010680) and locate the email field, currently set to admin@example.com. This value will be used for validation in the business rule.

Incident record INC0010680 with the email field set to admin@example.com, ready for validation
Incident record INC0010680 with the email field set to admin@example.com, ready for validation

Step 2: Add validation logic to the business rule

Open the demoBeforBusinessRule rule for the Incident [incident] table and go to the Advanced tab. Begin editing the script to add a conditional check comparing current.u_email to "admin@example.com", using the code completion dropdown to assist with field and method selection.

Step 3: Add an informational message for a valid email

Inside the if block, use gs.addInfoMessage() to display a message when the email matches the expected value:

if(current.u_email == 'admin@example.com') {
    gs.addInfoMessage("You are submitting the right value");
}
Business Rule editor with gs.addInfoMessage("You are submitting the right value") added inside the if block
Business Rule editor with gs.addInfoMessage("You are submitting the right value") added inside the if block

Step 4: Abort the action for an invalid email

Add an else block that uses current.setAbortAction(true); to abort the database action if the validation fails:

else {
    current.setAbortAction(true);
}

Step 5: Finalize the validation script

Ensure the complete script looks like this:

(function executeRule(current, previous /*null when async*/) {
    if(current.u_email == 'admin@example.com') {
        gs.addInfoMessage("You are submitting the right value");
    }
    else {
        current.setAbortAction(true);
    }
})(current, previous);

This script allows the form to submit and displays a success message when the email matches, and aborts the action — preventing the record from saving — when it doesn't.

Step 6: Test the validation logic

Return to the incident record and attempt to submit the form with the email field set to admin@example.com. If the email matches, the form submits and displays a message; if it doesn't match, the action aborts and an error is shown.

Incident record with the email field set to admin@example.com, ready for submission and validation
Incident record with the email field set to admin@example.com, ready for submission and validation

Step 7: Observe the validation result

If the email doesn't match the logged-in user's email, the business rule aborts the action and displays a message at the top of the form indicating an invalid record. This ensures only valid email values are accepted according to your business logic.

Business Rule editor showing the script with validation and abort logic, enforcing email validation
Business Rule editor showing the script with validation and abort logic, enforcing email validation

Set the email field automatically on update

Once validation is in place, you can update the script so it automatically populates the email field with the logged-in user's address whenever the record is updated.

Step 1: Update the script and save the rule

Open the demoBeforBusinessRule rule for the Incident [incident] table and confirm it's set to run before an update action. Go to the Advanced tab and update the script logic:

current.u_email = gs.getUser().getEmail();

Here, current refers to the record being updated, u_email is the field to be populated, and gs.getUser().getEmail() retrieves the logged-in user's email address. Right-click the form header and select Save from the context menu to save the rule.

Business Rule editor for demoBeforBusinessRule on the Incident table, Advanced tab open with the script editor visible and the Save option highlighted in the right-click context menu
Business Rule editor for demoBeforBusinessRule on the Incident table, Advanced tab open with the script editor visible and the Save option highlighted in the right-click context menu

Refresh the incident record and update it, for example by changing a field value or simply saving. The u_email field is automatically populated with the logged-in user's email address on update.

Test how the business rule handles an invalid email format

These steps demonstrate how the system responds when the email field contains a value the business rule doesn't recognize as valid.

Step 1: Open the incident record

Open the incident form with fields including Number INC0010680, Caller Bertie Luby, Category Inquiry / Help, Email admin@example.com, and the short description.

ServiceNow incident form with all fields visible, including the email field set to admin@example.com
ServiceNow incident form with all fields visible, including the email field set to admin@example.com

Step 2: Modify the email field

Click into the email field and change the value from admin@example.com to an invalid format, such as admin@example.comsssdddd.

Step 3: Attempt to save the record

Click the menu icon (three horizontal lines) at the top of the form and select Save from the dropdown menu to save the record and remain on the page.

Dropdown menu open with Save record and remain here highlighted, and the email field modified
Dropdown menu open with Save record and remain here highlighted, and the email field modified

Step 4: Observe the system's response

After the save attempt, a blue notification appears at the top of the form stating "You are submitting the right value," while the email field still contains the invalid value admin@example.comsssdddd.

Step 5: Attempt to save again

Click the menu icon and select Save once more.

Step 6: Review the error message

A red error notification appears at the top of the form stating "Invalid update." The system prevents the record from saving because of the invalid email format, and the record remains unsaved until the email field is corrected.

Red error notification "Invalid update" displayed, with the email field still containing an invalid value
Red error notification "Invalid update" displayed, with the email field still containing an invalid value

What's next

Now that you know how to create a business rule in ServiceNow, you can extend this pattern to other tables and fields by adjusting the When, Order, filter conditions, and script logic to fit your validation or automation needs. Consider testing additional scenarios, such as different trigger types (Insert, Delete, Query) or more complex validation conditions, to further automate record handling in your instance.

PowerPoint slide titled "Before Business Rule" with the text "BASICO SERVICENOW LEARING"
PowerPoint slide titled "Before Business Rule" with the text "BASICO SERVICENOW LEARING"
Generation details: cost, quality tiers

Docsie billed 6,000 credits ($4.20) to analyze this 12-minute video at standard quality. The rewrite, template fill and Word/PDF exports were included. The same video at each quality tier:

QualityFrames sampledCreditsApprox. cost
Draftevery 16-30 s3,000$2.10
Standard (this guide)every 8-15 s6,000$4.20
Detailedevery 4-7 s12,000$8.40
Ultraevery 1-3 s24,000$16.80

Credits priced at $0.70 per 1,000; plans include a monthly allowance. Enterprise customers on on-premise or bring-your-own-model deployments run this on their own inference and pay no per-video credits.

Generated by Docsie Video-to-Docs on 2026-09-14 from a 11-minute video. Screenshots are frames from the source video and belong to their creator, Basico ServiceNow Learning, whose original is embedded above. If you own this video and want the guide removed or credited differently, contact us and we will act within one business day.

Turn your own training videos into guidesJoin teams that save hours, reduce documentation work and scale training with Docsie.
See Docsie in action. No commitment.

Ready to Transform Your Documentation?

Start creating professional documentation that your users will love