setting the Due date on problem_task.

karunasrikuna
Tera Contributor

I need to set due date in the problem task form based on 5 Business days from the created date.

If it's Saturday (6) or Sunday (7) I need to move the date to Monday. I mean I need to skip the weekends and count only the working days to set the due date.

 

@Ankur Bawiskar Could you please help me on this ?

2 ACCEPTED SOLUTIONS

Sohail Khilji
Kilo Patron
Kilo Patron

Hi @karunasrikuna ,

 

go with a business rule with a below script : 

    var createdDate = new GlideDateTime(current.sys_created_on);
    var dueDate = new GlideDateTime();
    var businessDaysToAdd = 5; 
    while (businessDaysToAdd > 0) {
              dueDate.addDays(1);
          if (dueDate.getDayOfWeek() != 6 && dueDate.getDayOfWeek() != 0) {
            businessDaysToAdd--; 
        }
    }
    if (dueDate.getDayOfWeek() == 6) {
        dueDate.addDays(2); // Move to Monday
    } else if (dueDate.getDayOfWeek() == 0) {
        dueDate.addDays(1); // Move to Monday
    }
    current.due_date = dueDate;
    current.update();

 

 


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

View solution in original post

remove current.update() from script and retest.

View solution in original post

6 REPLIES 6

remove current.update() from script and retest.

Ankur Bawiskar
Tera Patron
Tera Patron

@karunasrikuna 

this link should help you add business days using schedule, please enhance it

Add Business Days 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader