SLA field value not updating when task sla changes

nickyjones
Kilo Contributor

Hi All, I have a business rule that copies the planned end time of a task sla into a field called SLA_due on the incident table. this is so I can have a field that shows the sla deadline based on colour. the problem I have is if the task sla planned end time changes because the priority has changed my field doesn't update with the new planned end time.   could someone take a look at the script and point me in the right direction of what is missing?  

var new_sla_due;

var gr = new GlideRecord("task_sla");

gr.addQuery("task", current.task);

gr.addQuery("stage", '!=', 'achieved');

gr.orderBy("planned_end_time");

gr.query();

if (gr.next())

{

  new_sla_due = gr.planned_end_time;

}

if (new_sla_due)

{

  var incidentRec = new GlideRecord('incident');

  incidentRec.addQuery('sys_id', current.task);

  incidentRec.query();

  if(incidentRec.next())

  {

  incidentRec.sla_due = new_sla_due;

  incidentRec.update();

  }

}

1 ACCEPTED SOLUTION

ProbirDas
Tera Expert

Set up the condition as in the screenshot. This is defined on task_sla table and 'before' insert and update operation.



Capture.JPG



//Script


var gr = new GlideRecord('incident');


gr.addQuery('sys_id',current.task);


gr.query();


if(gr.next())


{


        gr.sla_due = current.planned_end_time; //Make sure sla_due is the correct field name


        gr.update();


}


View solution in original post

9 REPLIES 9

Glad that I could help


This script trigger the incident   business rules.   that's   cause notification and other events that supposed to be run only when the incident is updated and not inserted, to run after insert also .   to avoid that i added gr.setWorkflow(false) to the script.


What about cancelled and completed? Should these stages also not be filtered out?


paradise623
Giga Expert

Hi Probir,



Can you also help me with this. I see your above example is running off incident. However I am using catalog task. Should I Change this?


iamsohail
Kilo Contributor

Hi Everyone



We have a similar requirement in populating the SLA due field, but we have two SLAs triggering at the same time for an Incident - Response SLA and Resolution SLA. What changes should I make in the code for the two possible solutions




  1. Once the incident is created, first the SLA due field should show the response SLA time, and once the response SLA is state moves to achieved, the SLA due field should update to resolution SLA time. This should also work when someone changes the priority later and the SLA due field should behave the same way with the new response and resolution times
  2. The SLA due field should always show only the resolution time from the moment the incident is created. When the incident priority is changed, the SLA due field should be updated to the new resolution time (In this solution, we should not be considering response time at all)


ProbirDas