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

Hi Kailash,



Currently, do you have an SLA set on Catalog Task table?



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

Hi sanjivmeher


I think i m not explaining things in the right way...Lets say, i m creating the catalog task using the catalog task activity.. In that case, i can set the schedule(24X5) and the number of days using the UI..



But now i m doing it through the script.. I want to calculate the due date now..



Lets say the SLA for my task is 5 days.. while calculating the due date i have to consider the 24X5 schedule before arriving at the due date.



The code in my original post creates the task programatically without any issues but the problem is with due date calculation.


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.

Thanks sanjivmeher



It worked..