We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Due date based on priority

solanovale
Tera Contributor

I am trying to get the due date in the catalog tasks to autopopulate depending on the priority. I have managed to make it work however, this should make the due date only dates that are M-F and exclude holidays. This is what I have so far but is not working any suggestions?

 

(function executeRule(current, previous /*null when async*/ ) {
    if (current.operation() != 'insert' && !current.priority.changes())
        return;
    var p = current.priority.toString();
    var hours;

    if (p === '1') hours = 6;
    else if (p === '2') hours = 12;
    else if (p === '3') hours = 36; //1 day + 12h
    else if (p === '4') hours = 60; //2 days + 12h
    else hours = 96; //4 days

    var sched = new GlideSchedule();
    sched.load('9edeb2281b314910d7a3a687624bcb9b');

    var start = new GlideDateTime();
    var durationMs = hours * 60 * 60 * 1000;

    var due = sched.add(start, durationMs);
    current.setValue('due_date', due);

})(current, previous);
1 REPLY 1

k_lutz
Giga Sage

Hi, 

Try this code. I did not test it out but I think the "add" function is meant to work with seconds and not milliseconds. Again, not 100% sure on that but give this a try and see if it works.