Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 10

BUSINESS RULES

• Business rules: 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.
• A business rule is a powerful feature that allows you to automate processes and enforce data integrity by executing scripts
based on certain conditions or events. Business rules can be applied at the table or field level and can execute server-side
scripts or client-side scripts.
• Here are some examples of how you can use business rules in ServiceNow:
• Data validation: You can use a business rule to validate data entered into a form or record before it is saved to the
database. For example, you can ensure that required fields are not empty, or that certain fields meet specific criteria.
• Workflow automation: You can use a business rule to trigger a workflow when a record is updated or created. For example,
you can automatically assign a task to a specific user based on the type of record or the value of a field.
• Data manipulation: You can use a business rule to modify data in a record based on certain conditions. For example, you
can automatically populate a field with a default value, or calculate the value of a field based on the values of other fields.
• Notification: You can use a business rule to send notifications to users or groups based on certain conditions. For example,
you can notify the IT department when a high-priority incident is opened, or notify a manager when an employee submits a
time-off request.
• 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.
• Time the business should run:
• BEFORE: After the user submits the form but before any action is taken on the record in the database.
• Before business rules allow you to validate data entered into a record, manipulate the data before it is saved to the database, or
enforce specific business rules or policies.
• Before business rules can be used to enforce data integrity, ensure data consistency, or enforce specific business rules or policies. For
example, you can use a before business rule to:
• Ensure that required fields are not empty before a record is saved to the database.
• Automatically calculate the value of a field based on the values of other fields before a record is saved to the database.
• Enforce specific business rules or policies before a record is saved to the database, such as ensuring that only users with specific roles
can modify certain fields.
• Once the before business rule is created, it will execute each time a record is inserted or updated in the database, before the record is
saved.
• AFTER: After the user submits the form and after any action is taken on the record in the database.
• After business rules are a type of business rule in ServiceNow that execute after a record is inserted or updated in the database. After
business rules allow you to validate data entered into a record, manipulate the data after it is saved to the database, or enforce
specific business rules or policies.
• After business rules can be used to enforce data integrity, ensure data consistency, or enforce specific business rules or policies. For
example, you can use an after business rule to:
• Automatically send notifications to users or groups after a record is saved to the database.
• Update related records or tables after a record is saved to the database.
• Enforce specific business rules or policies after a record is saved to the database, such as sending a notification to a manager when an
employee submits a time-off request.
• Once the after business rule is created, it will execute each time a record is inserted or updated in the database, after the record is
saved.
• ASYNC:
• Async business rules are like after business rule but it runs in the background simultaneously with other processes. Means
async business rule run after the data is saved into the database.
Running on background means that use can proceed with other functionality and code will run on the background which will
not impact the user while doing other transitions.
• For e.g. Incident ticket is in pending customer action status and will be auto closed after 5 days if user did not provide any
update on incident ticket.
• Use to update information on related objects that do not need to be displayed immediately, such as calculating metrics and
SLAs.
• Async business rules are useful when you need to execute time-consuming or resource-intensive operations, such as sending
emails or performing complex calculations, without delaying the user's interaction with the system. By executing the
business rule asynchronously, the user can continue working with the system while the background process is running.
• Once the async business rule is created, it will be added to the system's queue of background processes and executed when
resources are available. You can monitor the progress of async business rules in the "Asynchronous Business Rules" list.
• Display: Before the form is presented to the user, just after the data is read from the database.
• Display business rules are a type of business rule in ServiceNow that allow you to modify the display of form fields based on
specific conditions. Display business rules can be used to make fields visible, read-only, or mandatory based on the values of
other fields or conditions.
• Display business rules can be useful when you want to simplify the form interface for users by only showing them the fields
they need to complete based on their current context or situation. Display business rules can also be used to guide users
through a form by only showing them the fields they need to complete in a specific order.
• Once the display business rule is created, it will execute each time the form is loaded, and the display of the form fields will
be modified based on the conditions and actions defined in the business rule .
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.

Delete When the user deletes a record.

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.
• Aborting the current database transaction. For example, if certain conditions are met, prevent the
user from saving the record in the database.
• Global variables in business rules
• Predefined global variables are available for use in business rules.
• Use the following predefined global variables to reference the system in a business rule script.
• Global variables are variables that can be accessed from any part of a script, including business rules, in ServiceNow.
Global variables can be predefined by ServiceNow, such as the GlideRecord class, or they can be defined by the user.
• In business rules, global variables can be used to store values that are shared across multiple business rules or other
scripts. For example, you can use a global variable to store a reference to a specific record that is used in multiple
business rules, or to store a configuration value that is used throughout the system.
Global variable Description
current The current state of the record being referenced. Check for null before using this variable.

previous The state of the referenced record prior to any updates made during the execution context, where the execution context begins
with the first update or delete operation and ends after the script and any referenced business rules are executed. If multiple
updates are made to the record within one execution context, previous will continue to hold the state of the record before the
first update or delete operation. Available on update and delete operations only. Not available on asynch operations. 
Check for null before using this variable.

g_scratchpad The scratchpad object is available on display rules, and is used to pass information to the client to be accessed from client
scripts.

gs References to GlideSystem functions
• What is Glide
• Glide in ServiceNow is a set of JavaScript libraries and APIs that are used to customize and extend the functionality of the
ServiceNow platform.
• Glide can be used to create custom forms, lists, and UI pages, as well as to create custom business logic using JavaScript.
• Glide also allows developers to access and manipulate data stored in the ServiceNow database, and to integrate with other
systems and services.
• Glide system:
• The Glide system in ServiceNow is the core system that provides the foundation for the platform's functionality.
• It includes the Glide Record API, which is used to interact with the ServiceNow database, and the GlideForm API, which is
used to create and manage forms and lists.
• The Glide system also includes the Glide Ajax API, which allows developers to make asynchronous server-side requests, and
the Glide Ui API,(such as server-side business rules, data policies, and access controls) in a way that does not require a
page refresh. This can help improve the user experience by making the application feel more responsive and allowing for
dynamic updates to the UI.
• The GlideAjax API is accessed via the g_form.getXMLWait() method, which takes as its arguments the script name, the
input parameters, and a callback function to handle the response. The script name is the name of the script you want to
run on the server, the input parameters are passed to the script, and the callback function is executed when the server
returns the response.
• Using GlideAjax, developers can create more interactive, dynamic and responsive user interfaces. It can be used for
example to update a field on the current form based on the values of other fields, or to perform a server-side check or
validation that is too complex to perform client-side.
• Overall, Glide system provide developers with a wide range of tools and capabilities for creating custom solutions on the
ServiceNow platform.
Glide Record:
• Glide Record is a Java-like API in the Glide system of ServiceNow that is used to interact with data stored in the ServiceNow
database. It will executed on server side.
• Glide Record enables developers to query, update, insert, and delete records in the database, as well as to navigate
through the records returned by a query.
• The GlideRecord API is accessed via the new Glide Record() method, which takes as its argument the name of the table you
want to interact with. Once you have a Glide Record object, you can use its methods to perform various operations on the
data in the table.
• For example, to retrieve all records in a table, you can use the query() method, which takes no arguments. To retrieve a
specific record, you can use the get() method, which takes the unique sys_id of the record as an argument. To update a
record, you can use the setValue() method, which takes the field name and the new value as arguments. To insert a new
record, you can use the initialize() method and then set the values of the fields using the setValue() method. To delete a
record, you can use the deleteRecord() method.GlideRecord is a powerful and versatile API that is widely used to access
data stored in ServiceNow and perform various operations on it.
Glide record methods:
• Glide Record is a class in the ServiceNow platform that is used to query and manipulate data in the system. Some common
methods used with Glide Record include:
• initialize(): sets the Glide Record to a new query and sets the table name.
• Add Query(): adds a query to the Glide Record.
• query(): executes the query.
• next(): moves the cursor to the next record in the Glide Record.
• get(): retrieves the value of a field on the current record.
• set(): sets the value of a field on the current record.
• update(): saves the current record.
• insert(): inserts a new record.
• Delete Record(): deletes the current record These are some basic methods of Glide Record, but there are many more
available depending on your use case.
• Glide system methods:
• A glide system method is a method used to determine the possible solutions of a system of equations that
involve square roots or other radicals.
• getUser()
• getUserID()
• hasRole()
• getUserDisplayName()
• getUserName()
• What is glide API in Servicenow:
• Glide API is a collection of JavaScript classes and methods that allow developers to interact with the
ServiceNow platform and its underlying data.
• It provides a way to access and manipulate data in ServiceNow tables, create and modify records, run scripts
and business rules, and perform various other actions.
• The Glide API is built on top of the ServiceNow Script API and provides a simpler and more intuitive interface
for developers to work with.
• Some of the key features of the Glide API include:
• Access to ServiceNow tables and their fields. CRUD (Create, Read, Update, Delete) operations for
records.Client and server-side scripting capabilities. Business rule and workflow automation.
• Integration with external systems through REST APIs. Using the Glide API, developers can build custom
applications and integrations that leverage the power of the ServiceNow platform. It is widely used in
ServiceNow development and is an essential tool for building ServiceNow applications and integrations.

You might also like