Use of Display and Query business rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2015 12:19 AM
Can anyone tell me the use of display and query business rule.
Also whats the difference between the two?
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2015 12:27 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2015 12:55 AM
Two common use cases
Display - for when you want to run server side code onLoad
When an incident is opened, display the number of related open incidents.
Query - for removing the annoying 'results hidden from ACL'
An ACL is restricting 10 record in a list. The list says '10 records hidden by security' - I want it to show 0 record.
Create a query business rule that mimics the read ACL condition for that table.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
A Query Business Rule is one of the available operation types in Before, After, and Async Business Rules. It executes when the form is loaded and is used to filter the records that a user is allowed to see when querying a table. It works at both the form level and the list level.
For example, if you want the current logged-in user to see only those records where they are the caller or the assigned_to, you can write:
Use Case
If you want the logged-in user to see only those records where they are the caller or the assigned_to, you can write:
Steps
Go to Business Rules
Create a new rule → Before Business Rule
Open the Advanced view
Set When to run = Query
In the Script field: current.addQuery('caller', gs.getUserID()); // Filter records where logged-in user is caller
// OR
current.addQuery('assigned_to', gs.getUserID()); // Filter records where logged-in user is assigned_toResult
When the user logs in and opens the list view, they will see only those records in which:
They are the caller, or
They are in assigned_to.
Display Business Rule
A Display Business Rule runs when a form is loaded.
It does not support operations like insert, update, delete, or query.
It is mainly used to:
Fetch information from the server
Send it to the client script
For this, we use g_scratchpad, which is an empty object available on both server and client.
Example – Show Logged-in User’s Name
Create a Display Business Rule
In the Script field:
g_scratchpad.name = "Vipin Dimri"; // Passing a hardcoded value to the client
In the Client Script (onLoad):
alert(g_scratchpad.name);
Display BR Without g_scratchpad
Sometimes Display BR is used only to pre-populate fields and doesn't need g_scratchpad.
For example, populating Problem Task fields from the related Problem record.
Use Case – Populate Problem Task with Problem Data
current.problem != "" && current.isNewRecord()
current.assignment_group = current.problem.assignment_group;
current.short_description = current.problem.short_description;
