Display BR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2025 01:59 AM
create a display business rule to show number of related tasks in a table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2025 02:12 AM
Go check this out:
Display Business Rule and g_scratchpad - ServiceNow Community
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2025 02:55 AM
Lets say you want to count no of related incidents on task table, below is display BR:
var taskCount = 0;
var grTask = new GlideRecord('task'); // Fetch tasks related to the incident
grTask.addQuery('parent', current.sys_id); // Parent field links tasks to incident
grTask.query();
if (grTask.hasNext()) {
taskCount = grTask.getRowCount();
}
gs.addInfoMessage(taskCount);
Please mark correct/helpful if this helps you!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2025 03:12 AM
Hello @Apaul ,
I hope you are good.
If someone ever asks you about write or tell how to fetch the count it is always best practice to use GlideAggregate.
var taskCount = 0;
var aggTask = new GlideAggregate('task'); // Use GlideAggregate to count tasks efficiently
aggTask.addQuery('parent', current.sys_id); // Filter tasks related to the current incident
aggTask.addAggregate('COUNT'); // Aggregate function to count records
aggTask.query();
if (aggTask.next()) {
taskCount = aggTask.getAggregate('COUNT'); // Get the count value
}
gs.addInfoMessage(taskCount);
the above script will give you the count of tasks.
Display Business rule: This type of business rule can be used in different scenarios
One example Whenever a kb article is loaded /viewd you want to increase the view count in this case you can use a display business rule to achieve this.
(function executeRule(current, gsr, gs) {
// Increment the view count for the KB article
current.view_count = (current.view_count || 0) + 1;
current.update(); // Save the updated view count
})(current, gsr, gs);
Runs before the KB article is sent to the user.
Increments the view_count field by 1 every time the article is loaded.
Uses current.update(); to save the new count back to the database.
Business rule - https://www.servicenow.com/docs/bundle/yokohama-api-reference/page/script/business-rules/concept/c_B...
Please Mark it as correct/helpful if this helps you