Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Change the text colour of Incident number.

gourav2
Kilo Expert

When the SLA is about to expire for a particular P1 incident, the colour of the Incident number text will change.

This is only for tickets where the SLA is ticking, not for pending status incidents.

Example:

3 hours SLA left: Orange

2 hours SLA left: Yellow

1 hour SLA left: Red

Would anyone like to give a hint on this? I tried writing a Script Include and then changed the Field Styles but it didn't work.

Below is the example which I took from the Community itself:

var CheckSLAState = Class.create();

CheckSLAState.prototype = Object.extendsObject(AbstractAjaxProcessor, {

   

      isSLAInProgress : function(incidentSysID) {

           

              var checkSLA = new GlideRecord("task_sla");

              checkSLA.addQuery("sla", 'cce4464f0f4f4600db7e715ce1050ed0');

              checkSLA.addQuery("task", incidentSysID);

              checkSLA.addQuery("stage", 'in_progress');

              checkSLA.query();

              if (checkSLA.next()) {

                      return true;

              }

              return false;

           

      }

});

-----------------------------------------------

Field Style: javascript: var checkValue = (new CheckSLAState().isSLAInProgress(current.sys_id)); checkValue   == true;

Thanks for any help.

5 REPLIES 5

Thanks a lot Mike. I tried doing that even, but its not working. There maybe some issue with the logic. However I tried doing the same using a Scheduled Job but that too went in vain. Below is the script for that:



function changeColour()


{


var checkSLA = new GlideRecord('task_sla');


checkSLA.addQuery("sla", 'EKAB Remote Support P1 Software');


checkSLA.addQuery("stage", 'in_progress');


//Add a query for time_left here;


var textNumber = $('sys_display.incident.number');


var time1 = current.duration;


var time2 = current.start_time;


var Diff = gs.dateDiff(time1, time2, true);


checkSLA.query();


while(checkSLA.next())


{


  if(Diff <= 10800)


  {


    textNumber.setStyle({color: "Orange"});


  }


  else if(Diff <= 7200)


  {


    textNumber.setStyle({color: "Yellow"});


  }


  else if(Diff <= 3600)


  {


    textNumber.setStyle({color: "Red"});


  }


}


return false;


}