đ Show Info Message When SLA Is Outside Business Hours
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10 hours ago - last edited 10 hours ago
In some scenarios, SLAs are configured with business schedules, meaning the SLA timer should run only during business hours. When a user updates a record outside the defined schedule, the SLA is paused â but users may not know why the timer is not running.
This article explains how to show an info message on the form when the current time is outside the SLA schedule, using:
Display Business Rule
g_scratchpadOnLoad Client Script
GlideSchedule API
This approach helps users understand why the SLA is paused.
Requirement
Show an info message on the form:
"Note: You are currently outside business hours. SLA timers will be paused during this period."
when:
The record has an active SLA
The SLA has a schedule
Current time is outside the schedule
Step 1 â Create Display Business Rule
A Display Business Rule is used to check SLA schedule and pass the result to the client using g_scratchpad.
Business Rule Details
Name:
Check SLA ScheduleTable: Task (or Incident/case / any task table)
When: Display
Advanced: â Checked
Script
(function executeRule(current, previous /*null when async*/ ) {
// Initialize the scratchpad variable
g_scratchpad.outside_business_hours = false;
// Query active SLAs for current record
var slaGR = new GlideRecord('task_sla');
slaGR.addQuery('task', current.sys_id);
slaGR.addQuery('stage', 'in_progress');
slaGR.query();
while (slaGR.next()) {
var slaDef = slaGR.sla.getRefRecord();
if (slaDef && slaDef.schedule) {
var schedule = new GlideSchedule();
schedule.load(slaDef.schedule.sys_id);
var now = new GlideDateTime();
// Check if current time is outside schedule
if (!schedule.isInSchedule(now)) {
g_scratchpad.outside_business_hours = true;
break;
}
}
}
})(current, previous);Explanation
Gets active SLA from
task_slaReads SLA definition schedule
Uses
GlideSchedule.isInSchedule()Stores result in
g_scratchpadScratchpad value is available in client script
Step 2 â Create OnLoad Client Script
This script reads the value from scratchpad and shows message on form.
Client Script Details
Name:
Display Scratchpad Business Hours- Table: Task (or Incident/case / any task table)
Type: onLoad
UI Type: All
Script
function onLoad() {
if (g_scratchpad.outside_business_hours) {
g_form.addInfoMessage(
'Note: You are currently outside business hours. SLA timers will be paused during this period.'
);
}
}Explanation
Runs when form loads
Checks scratchpad value
Displays info message using
g_form.addInfoMessage()
How It Works
Form loads
Display Business Rule runs on server
SLA schedule is checked
Result stored in
g_scratchpadClient script runs onLoad
Message shown if outside schedule
Conclusion
Using a Display Business Rule + Scratchpad + Client Script, we can easily inform users when the current time is outside the SLA schedule.
This improves transparency and reduces confusion when SLAs pause during non-business hours.
