how to add 2 business days to a current date and time and place it in another field using schedule

Renu9
Tera Contributor

Hi All,

I am writing a script in Run script activity in workflow to add 2 business days to current date and time and place it in a field. But my script is not returning proper value. It is throwing an error

Could you please guide

 

var scTask = new GlideRecord("sc_task");
scTask.addEncodedQuery("state=2"); //if state is work in progress
scTask.query();
if (scTask.next()) {
   
var startDate= gs.nowDateTime();
var days = 2;
//assuming there are 8 business hours
days = days*8;
var dur = new GlideDuration(60 * 60 * 1000 * days); 
var schedule = new GlideSchedule('f4db82011b36a010cb721f42b24bcb27'); //put your schedule sys_id here
 var end = schedule.add(startDate, dur);
scTask.field1=end;
    
}

1 ACCEPTED SOLUTION

Murthy Ch
Giga Sage

hi @Renu

Try this:

var scTask = new GlideRecord("sc_task");
scTask.addQuery("request_item", current.sys_id); //added here
scTask.addEncodedQuery("state=2"); //if state is work in progress
scTask.query();
if (scTask.next()) {
var startDate= new GlideDateTime(); //changed here
var days = 2;
//assuming there are 8 business hours
days = days*8;
var dur = new GlideDuration(60 * 60 * 1000 * days); 
var schedule = new GlideSchedule('f4db82011b36a010cb721f42b24bcb27'); //put your schedule sys_id here
 var end = schedule.add(startDate, dur);
scTask.field1=end;
scTask.update();  //added here
}

 

Thanks,

Murthy

Thanks,
Murthy

View solution in original post

5 REPLIES 5

Naga Ravindra R
Kilo Sage

I think you just need to add an Update condition like scTask.update(); 

It will tell the script to update. 🙂