Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

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

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

Kieran Anson
Kilo Patron

There is more than likely a schedule [cmn_schedule] already in the system for you to use. You can then leverage the GldieSchedule API to add 5 business days, it'll auto-skip over non-business days based on the provided schedule

 

GlideSchedule | ServiceNow Developers

Sohail Khilji
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

Hi @Sohail Khilji 

I have used this BR , but now i am facing this issue. Can you please help me on this. Attaching the screenshots. Can you please help me ASAP.

This due date should be auto populate only under certain conditions. I have created a flow designer for that . I am attaching the screenshots of flow designer as well.