📘 Show Info Message When SLA Is Outside Business Hours

kasulavarshini
Tera Explorer

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_scratchpad

  • OnLoad 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 Schedule

  • Table: 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_sla

  • Reads SLA definition schedule

  • Uses GlideSchedule.isInSchedule()

  • Stores result in g_scratchpad

  • Scratchpad 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

  1. Form loads

  2. Display Business Rule runs on server

  3. SLA schedule is checked

  4. Result stored in g_scratchpad

  5. Client script runs onLoad

  6. Message shown if outside schedule

 

         image (4).png

 

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.

 

0 REPLIES 0