Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

SLA due is showing UNKNOWN

Naveen31
Giga Contributor

SLA Due is showing Unknown, So based on created field SLA due should auto populate but it will included 48 hours Example: Created is 2020-07-27 13:26:58 So SLA Due should be 2020-07-29 13:26:58

find_real_file.png

3 REPLIES 3

Namrata Khabale
Giga Guru

I have written below script but its not working

var gr = new GlideRecord("sc_task");
gr.addQuery("task", current.sys_id);
gr.orderBy("sys_created_on");
gr.query();
if (gr.next()) {
//gs.addInfoMessage("sys_created_on " + gr.sys_created);
current.sla_due = gr.sys_created_on;
current.update();
}

find_real_file.png

Community Alums
Not applicable

Hi Please try the below business rule and code

1. create a business rule on SLA task table

Aurobinda1_0-1741386627555.png

 

 

Script:- 

(function executeRule(current, previous /*null when async*/ ) {

   // if (current.task && current.completion_date) {
   
        var taskGR = new GlideRecord('task'); // Replace 'task' with your specific task table if needed
        taskGR.addQuery('sys_id', current.task); // Query the task based on sys_id
        taskGR.query();

        if (taskGR.next()) { // If a matching task is found
   
            // Update the SLA due date field in the incident (task) record
            taskGR.sla_due = current.planned_end_time; // Copy the completion date to SLA due
            taskGR.update(); // Save the changes to the task record
        }
  //  }

})(current, previous);