SLA Status in incident form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2023 09:47 PM
Hi All,
I want to add the status of incident whether it breached SLA or not in incident form. How can we achieve this,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2023 10:04 PM
Hi @JPSS ,
I trust you are doing great.
In order to achive this use case please follow below steps
- Create a choice field on the incident table to store the sla breached status and pull it to the form.
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2023 10:59 PM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2023 11:42 PM
I would suggest you create a custom True/False field on the incident table
Then create a business rule on TASK SLA (task_sla) table with the following When to Run Condition
Then add the following code:
var grIncident = new GlideRecord('incident');
if (grIncident.get(current.task)) {
grIncident.u_sla_breached = true;
grIncident.update();
}
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2023 11:50 PM
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/