Populate the SLA breach time on incident
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2022 08:55 AM
Hi All,
I have a requirement where I need to populate the sla breach time on a custom field on incident table.
When there are two or more resolution SLAs for the same incident then the field should have the min sla breach time.
Please suggest on how to implement this.
I have created a BR on insert of update of TASK SLA table where the task type is incident and target is resolution.
Unable to find a logic to create the code.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2022 12:00 PM
Hi Madhu,
Here's how it can be done:
1) Define the custom field on the task table, i.e. SLA Target (u_sla_target)
2) Create a new event "task.update.sla.target" in the System Policy > Events > Registry
3) Create a new script action "Update task sla target" in the System Policy > Events > Script Actions
Make that script action fires on event "task.update.sla.target" with this script:
(function (current,event) {
var pendingDate = '';
var sla = new GlideRecord("task_sla");
sla.addQuery("task", current.sys_id);
sla.addQuery("stage","in_progress");
sla.orderBy("planned_end_time");
sla.query();
if (sla.next()) {
pendingDate = sla.getDisplayValue("planned_end_time");
}
current.u_sla_target.setDisplayValue(pendingDate); /* Handle time zones */
current.setWorkflow(false);
current.update();
})(current,event);
4) Create a new business rule "Calc - SLA Target (Raise event)" in System Definition > Business Rules
Running After Insert and Update, Order = 10,000
Conditions: Task.Task type is Incident and ( Stage changes or Breach time changes )
with following script:
(function executeRule(current, previous /*null when async*/) {
/* Set "SLA Target" field: */
/* - Set it to the earliest date/time from all "in_progress" SLA's. */
/* - If no "in_progrees" SLA's, set it to blank. */
var rec = current.task.getRefRecord();
gs.eventQueue('task.update.sla.target',rec);
})(current, previous);
5) Add the custom field "SLA Target" on Incident form and/or list.
Regards.
JP
JP