๐ Scenario-Based Question
Q1: How can you display inactive incidents only to ITIL Admins and hide them from all other users?
Answer:
1๏ธโฃ Method 1: Create a Read ACL for Inactive Incidents๐ Purpose: Restrict access to inactive incidents only for users with the itil_admin
role.
๐ง Setting | โ๏ธ Value |
---|---|
Table | incident |
Operation | read |
Condition | Active = false |
Roles | itil_admin only |
โ Result: Only ITIL Admins can view inactive incidents; all other users wonโt see them in lists, reports, or queries.
๐ Purpose: Dynamically filter out inactive incidents for non-admins using scripting.
๐งฐ Script Example:
// Table: incident
if (!gs.hasRole('itil_admin')) {
current.addQuery('active', true);
}
Explanation:
This script adds a filter to the query so that only active incidents are shown unless the user has the itil_admin
role.
โ Result: Clean and dynamic approach that works behind the scenes.
2๏ธโฃ Method 2: Use a Before Query Business Rule
๐ฏย Recommended Approach:- Useย Query Business Rule if you want better performance and centralized logic.
- Useย ACLs for fine-grained security enforcement.
ย
Q2: Write a background script to count incidents for which SLA has been breached?
Answer:
Hereโs a clean and efficient background script to count breached SLAs for incidents using GlideAggregate:
var slaBreached = 0;
var slaGr = new GlideAggregate("task_sla");
// ๐๐ฎ๐๐ซ๐ฒ ๐๐จ๐ซ ๐๐ซ๐๐๐๐ก๐๐ ๐๐๐๐ฌ ๐ซ๐๐ฅ๐๐ญ๐๐ ๐ญ๐จ ๐ข๐ง๐๐ข๐๐๐ง๐ญ๐ฌ
slaGr.addQuery("task.sys_class_name", "incident");
slaGr.addQuery("has_breached", true);
slaGr.addAggregate("COUNT");
slaGr.query();
// ๐
๐๐ญ๐๐ก ๐ญ๐ก๐ ๐๐จ๐ฎ๐ง๐ญ ๐๐ข๐ซ๐๐๐ญ๐ฅ๐ฒ ๐ฐ๐ข๐ญ๐ก๐จ๐ฎ๐ญ ๐ฅ๐จ๐จ๐ฉ๐ข๐ง๐
if (slaGr.next()) {
slaBreached = slaGr.getAggregate("COUNT");
}
// ๐๐ซ๐ข๐ง๐ญ ๐ญ๐ก๐ ๐ซ๐๐ฌ๐ฎ๐ฅ๐ญ
gs.print("Count of incidents with breached SLAs: " + slaBreached);
๐ Explanation:
- ๐น Filters for
task.sys_class_name = incident
to ensure only Incident SLAs are included. - ๐น
has_breached = true
to select only breached SLA records. - ๐น Uses
GlideAggregate
for performance, returning the count directly.