SLA Status in incident form

JPSS
Tera Contributor

Hi  All,

 

I want to add the status of incident whether it breached SLA or not in incident form. How can we achieve this,

4 REPLIES 4

Amit Gujarathi
Giga Sage
Giga Sage

Hi @JPSS ,

 

I trust you are doing great.

In order to achive this use case please follow below steps

  1. Create a choice field on the incident table to store the sla breached status and pull it to the form.
  2. Then write a script to check if the SLA are bridge or now for an incdent and use it to update the status 

 

var gr = new GlideRecord('incident');
gr.addQuery('number', 'INC001234'); // Replace INC001234 with the incident number you want to check
gr.query();

if (gr.next()) {
  var sla = new GlideRecord('contract_sla');
  sla.addQuery('name', gr.getValue('sla')); // Assumes that the SLA field on the incident form is a reference field to the 'contract_sla' table
  sla.query();

  if (sla.next()) {
    var slaGr = new GlideRecord('task_sla');
    slaGr.addQuery('task', gr.getUniqueValue());
    slaGr.addQuery('sla', sla.getUniqueValue());
    slaGr.query();

    if (slaGr.next()) {
      if (slaGr.getValue('breached') == 'true') {
        gs.log('SLA has been breached');
      } else {
        gs.log('SLA is still within the time limits');
      }
    }
  }
}​

 

Please Mark My Response as Correct/Helpful based on Impact

 

Regards,

Amit Gujarathi


Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Ankur Bawiskar
Tera Patron
Tera Patron

@JPSS 

why to create a new field on incident when it can be seen on related list?

If you still want to use then create True/False field on incident and use this

1) Display business rule on incident table

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var rec = new GlideRecord('task_sla');
	rec.addQuery('task', current.getUniqueValue());
	rec.addQuery('stage','breached');
	rec.query();
	g_scratchpad.isBreached = rec.hasNext();

})(current, previous);

2) onLoad client script

function onLoad(){
	
	if(!g_form.isNewRecord())
		g_form.setValue('fieldName', g_scratchpad.isBreached);
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Sufiyan Memon
Kilo Sage
Kilo Sage

@JPSS 

 

I would suggest you create a custom True/False field on the incident table

SufiyanMemon_3-1677137924893.png

 

Then create a business rule on TASK SLA (task_sla) table with the following When to Run Condition

SufiyanMemon_0-1677137728110.png

Then add the following code:

var grIncident = new GlideRecord('incident');
	if (grIncident.get(current.task)) {
		grIncident.u_sla_breached = true;
		grIncident.update();
	}

SufiyanMemon_1-1677137802846.png

I created this demo in my PDI and it is working. Let me know if you will face any difficulty while achieving this.

 

If this worked for you, please mark it correct.

Regards

Sufiyan Memon

AndersBGS
Tera Patron
Tera Patron

Hi @JPSS ,

 

I would not recommend doing this, as the information is already available on the SLA related list. 

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

Best regards

Anders

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/