Setting the planned due date for task using script

kailashthiyagar
Kilo Guru

We can write script to set the task due date dynamically as like below. but i would like to how to set the schedule to 24X5 using this approach..

var grTask = new GlideRecord('sc_task');

var date=new Date();

var gdt = new GlideDateTime();

gdt.addDays(2);

// grTask.assignment_group=sloGrp;

grTask.initialize();

grTask.short_description = 'This is a test record';

grTask.request_item=current.sys_id;

grTask.due_date=gdt;

grTask.insert();

I refer this part of the schedule in the   catalog tasks. Usually we wil set 24X5 when we do it through catalog task activity.. When it comes to script, how we can do it?

find_real_file.png

1 ACCEPTED SOLUTION

Ok. I get you now. You are not using the SLA module. You just want to set a due date with 5 days SLA with 24*5 schedule.



Try the below script



var days = 5;


var dur = new GlideDuration(60 * 60 * 24 * 1000 * days);


var schedule = new GlideSchedule('sys id of the 24*5 schedule');


current.due_date = schedule.add(currentDateTime, dur);



Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

8 REPLIES 8

sachin_namjoshi
Kilo Patron
Kilo Patron

Please use below to add schedule while calculating dates.



Using DurationCalculator To Calculate a Due Date - ServiceNow Wiki



Regards,


Sachin


sachin.namjoshi



sorry for the delay in response. I m little bit confused on how to use the durationCalculator script include to compute the dute date by specifying the number of days, and the schedule.. could you give example?



Looping sanjivmeher and pradeepksharma


Jaspal Singh
Mega Patron
Mega Patron

Hi Kailash,



If you already have a scheduled defined you can have below after business rule written on task_sla table.



//function onAfter(current, previous) { //Kindly keep the function commented




var gr = new GlideRecord('table_name');


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


gr.query();


while(gr.next())


{


gs.log('Task is ',current.task.getDisplayValue());


gs.log('Due date is ',current.planned_end_time); //Planned end time calculates values based on schedule it is associated with


gr.due_date = current.planned_end_time;


gr.setWorkflow(false);


gr.update();


}


//}


jaspalsinghchot



I dont have a schedule defined... what i would like to do exactly is, i want to calculate the due date based on "24X5" schedule and the number of days..



Say for example the number of days defined for completing a task is 5.. i want to calculate due date based on the SLA of 5 days for the schedule "24X5"