We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

"SLA Reason Section"

Blitz
Tera Expert

Do you know how to implement use case: If Task SLA [has_breached] is false then the "SLA Breached Reason" section & "Breached Reason" field will not display, I think this can be done in an On load Client script

Just a sample: 

Blitz_0-1723610396149.png

 

1 ACCEPTED SOLUTION

Hemanth M1
Giga Sage

Hi @Blitz ,

 

Write a onload client script and call the script incude using GlideAjax to check if any of the SLA assosciated to the incident is breached or not , if not breached hide the section

 

Note: Section name must in be in lowercase while hidding and also replace firsr space with unserscore and remove next spaces ex: SLA Breached Reason becomes

g_form.setSectionDisplay("sla_breachedreason", false);

 

client scritpt:

function onLoad() {
    //Type appropriate comment here, and begin script bel
    var inc = new GlideAjax("checkSLA");
    inc.addParam("sysparm_name", "breachStatus")
    inc.addParam("id", g_form.getUniqueValue());
    inc.getXMLAnswer(result);

    function result(output) {
        if (output== "not breached") {
            g_form.setSectionDisplay("related_records", false); //replace related_records with your section name
        }
    }

}

Script include:

var checkSLA = Class.create();
checkSLA.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    breachStatus: function() {
        var incSysId = this.getParameter("id");
        var sla = new GlideRecord("task_sla");
        sla.addQuery("task", incSysId);
        sla.query();
        while (sla.next()) {
            if (sla.has_breached) {
                return "breached"; //any one of the SLA is breached
            }
        }
        return "not breached"; //no SLA breached

    },

    type: 'checkSLA'
});

 

ex:

 

HemanthM1_0-1723620775627.png

 

HemanthM1_1-1723620818359.png

 

Hope this helps

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

View solution in original post

6 REPLIES 6

Slava Savitsky
Giga Sage

Use a display business rule to query Task SLA table, check the value of "has_breached" attribute and save the result in g_scratchpad variable. Then use setSectionDisplay method of the g_form API in an onLoad client script to show or hide "SLA Breached Reason" section depending on the value saved in g_scratchpad.

Its also a great idea do you have a sample? 

Hemanth M1
Giga Sage

Hi @Blitz ,

 

Write a onload client script and call the script incude using GlideAjax to check if any of the SLA assosciated to the incident is breached or not , if not breached hide the section

 

Note: Section name must in be in lowercase while hidding and also replace firsr space with unserscore and remove next spaces ex: SLA Breached Reason becomes

g_form.setSectionDisplay("sla_breachedreason", false);

 

client scritpt:

function onLoad() {
    //Type appropriate comment here, and begin script bel
    var inc = new GlideAjax("checkSLA");
    inc.addParam("sysparm_name", "breachStatus")
    inc.addParam("id", g_form.getUniqueValue());
    inc.getXMLAnswer(result);

    function result(output) {
        if (output== "not breached") {
            g_form.setSectionDisplay("related_records", false); //replace related_records with your section name
        }
    }

}

Script include:

var checkSLA = Class.create();
checkSLA.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    breachStatus: function() {
        var incSysId = this.getParameter("id");
        var sla = new GlideRecord("task_sla");
        sla.addQuery("task", incSysId);
        sla.query();
        while (sla.next()) {
            if (sla.has_breached) {
                return "breached"; //any one of the SLA is breached
            }
        }
        return "not breached"; //no SLA breached

    },

    type: 'checkSLA'
});

 

ex:

 

HemanthM1_0-1723620775627.png

 

HemanthM1_1-1723620818359.png

 

Hope this helps

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

Although this is a valid approach, using a display business rule is better in terms of performance than making a GlideAjax call as it does not require a extra round-trip to the server.