Business Rule Assignment
BY – Sagar Ravandale
Q. Define Business Rule
- A Business Rule (BR) in ServiceNow is a server-side script that runs whenever a record is
inserted, updated, deleted, displayed, or queried from a table.
- Business Rule is Pure Server Side Code.
- To automate the processes from server side we use Business Rules.
- Business Rule by default work as before business rule
- BR is server side code which is written in javascript and which only uses server side API’s.
- API’s like - GlideRecord, GlideSystem, GlideDateTime, GlideAgregate, GlideSecure etc are
used.
- This server side code is used to perform CRUD(Create, Retrieve, Update, Delete) operations
against the records which are in the table which are being displayed, inserted, updated,
deleted, queried.
- BR has 4 types - Before, After, Async, Display.
Q. Explain the difference between after and async BR
After BR Async BR
After BR is Synchronous Async BR is Asynchronous
Current and previous objects are is Only current object is
executable executable
Used for Real time implementation Used for Non real time implementation
May not affect the performance of the
May impact the performance of the system
system
Ex. - Use After BR to propagate change from Ex. - Use Async BR to invoke web services
parent record to child record through the REST API
Q. Explain Display BR with 2 or 3 practical Example.
- Display BR executes their logic when a form loads and a record is loaded from the database so
that it can be available at client side.
-display business rule is used to make the server side data to be available in the client side
- The value we get from display BR is only available on the onChange Client Script.
Ex – When we open a incident form to create a new incident, like we want the location field will
be filled automatically based on chosen department for the user.
So, by using Display BR we can check the users department and according to that we update
the location field.
Ex. When we create a new incident the priority is set to 5-Planning. As the value of impact and
urgency is set to 3 – low then this priority(5) is displayed to the user using the display BR.
Q. List down the API that are allowed in BR
- 1. GlideRecord() - Used to query, insert, update, or delete records in a table.
- 2. GlideSystem() - Used for logging, getting user info, system info etc.
- 3. GlideDateTime() - Used to work with dates and times.
- 4. GlideAggregate() - Used to calculate counts, sum and other aggregates.
- 5. GlideUser – Used to get the user information.
Q. Explain the use of setWorkflow(false)
- Using this method when we have to update a record it can be used to trigger workflows.
- By using setWorkflow(false) - it tells us that update the current record without triggering the
workflow.
- Like it will disable the workflow for that operation.
- one of use case when we have to use [Link]() in Business Rule.
Q. Explain the hazards of [Link]()
- The [Link]() in Business Rule results into the rescursion.
- When we call [Link]() inside a before or after BR it can trigger the same BR again and
again and this will create an infinite loop.
- It can cause system crash
- updating using this method can call another workflow of BR which cause harm.
- we can [Link](false) before update to prevent extra triggers.
Q. Enlist 30 important methods of glideRecord
1) addQuery() To add a condition to the query.
2) addEncodedQuery() Add a query using encoded query.
3) addActiveQuery() Adds a filter to return active records.
Add a filter to return records based on relationship of
4) addJoinQuery()
fields in table
5) addNotNullQuery() Returns the records where the value of field is not null.
6) addNullQuery() Returns the records where the value of field is null.
To do add or subtract operation based on specific
7) addValue()
number field.
Used to check if a specific user can has rights to create
8) canCreate()
records
Used to check if a specific user can has rights to delete
9) canDelete()
records
Used to check if a specific user can has rights to read
10) canRead()
records from the table
Used to check if a specific user can has rights to edit
11) canWrite()
records in the table
12) deleteMultiple() Used to Deletes all records that satisfy the query.
13) deleteRecord() Used to delete the current record.
14) Get() Returns the specified record in the current GR object.
15) getDisplayValue() Shows the Display Value for current record.
16) getLabel() Used to Return the field's label.
17) orderByDesc() Specifies a descending orderBy column.
18) orderBy() Specifies an orderBy column.
19) getRowCount() Returns the number of rows
20) getTableName() Retrieves the name of the table associated with the GR.
21) getValue() Returns the String Value
22) hasNext() To check if there is any more records available
23) initialize() Creates an empty record
24) insert() Inserts a new record using the field values
To check whether the specified encoded query is valid or
25) isEncodedQueryValid()
not
26) isNewRecord() Used to check if the current record is a new record or not
Runs a query against the table based on the filters
27) Query()
specified
28) newRecord() Used to create Creates a new GlideRecord record
29) next() Used to move to next record
Sets the value of the field with the specified name to the
30) setValue()
specified value.
Q. Enlist 15 important methods of glideSystem
1) AddErrorMessage() Adds an error message for the current session.
2) AddInfoMessage() Adds an info message for the current session.
3) generateGUID() Used to Generate GUID (sys_id) when required
Returns the name of the time zone associated with the
4) getTimeZoneName()
current user.
5) getUserDisplayName() Returns the display name of the current user.
6) getUserID() Returns the sys_id of the current user.
7) getUserName() Returns the user name of the current user.
8) hasRole() Used to check if a user has specific role.
9) info() Writes an info msg into the system logs
10) isLoggedIn() Used to check if the current user is currently logged in.
11) tableExists() Used to check if a database table exists or not
12) warn() Writes an warning msg into the system logs
13) yesterday() Returns yesterday's time
14) isMobile() Used to check if a request is coming from a mobile device
15) getTimeFormat() Returns the time format of the current user.