How do I highlight an Incident where the SLA breaches in the next 2 days
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2018 01:30 AM
I want to highlight the Incident.Number field when the Incident's SLA breach time is within the next business day. I'm thinking I should be able to appliy a Field Style based on the current Task_SLA Business Time Left being less than a specified number of seconds. Is this correct? What is the syntax that I would need to apply to the Value field?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2018 02:10 AM
As there's a one-to-many relationship between tasks and task_sla records, you'd need to write a script include to query the child SLAs and return true if any of them are within the time boundary. The code in your field style would be:
javascript:new MyScriptInclude().myMethod(current);
And your Script Include a little something like this:
var MyScriptInclude = Class.create();
MyScriptInclude.prototype = {
initialize: function() {
},
// Query all child task SLAs and return true if any are within boundary
myMethod: function(current) {
var timeBoundaryMS = 1000 * 60 * 5; // 5 minutes in ms
var sla = new GlideRecord("task_sla");
sla.addQuery("task", current.sys_id);
sla.addQuery("stage", "in_progress");
sla.query();
while(sla.next()) {
var businessTimeLeft = new GlideDateTime(sla.business_time_left);
var businessTimeLeftMS = businessTimeLeft.getNumericValue();
if(businessTimeLeftMS < timeBoundaryMS)
return true;
}
return false;
},
type: 'MyScriptInclude'
};
The following API documentation for GlideDateTime should help you should you need it:
https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=c_APIRef
I haven't tested this but it should be pretty accurate.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2018 03:46 AM
Following on from Adams post I tried it out and it works fine
the only changes I made was
var timeBoundaryMS = 1000 * 60 * 60 * 8; // 8h in ms adjust for the length of your business day
and
if((businessTimeLeftMS < timeBoundaryMS)&&(businessTimeLeftMS > 0)) only triggers if it's not already failed
Now this is quite nice as you can extend the script include with more methods and so have a range of styles you just need to build out the conditions and ensure they don't overlap.
Nice job Adam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2018 04:16 AM
No worries, I knocked that example together pretty quickly but your enhancements are an obvious improvement. It may also be an idea to get the value of timeBoundaryMS into a system property so it can be updated in the future without need for a code change.
Please mark my answer as correct if you have now successfully solved the problem, cheers!