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

brian_quinn
ServiceNow Employee
ServiceNow Employee

Nicky,



As a starting point, can you provide some more details about the business rule?   Is it a before or after?   Insert and Update of the incident table?



Thanks


Brian


Hi Brian,   sorry for the late reply.   my rule is run after and on insert or update


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();


}


thanks for your info that really helped fixing this for me as I was going a bit mad.