Skip to page contentSkip to chat
ServiceNow support
    • Community
      Ask questions, give advice, and connect with fellow ServiceNow professionals.
      Developer
      Build, test, and deploy applications
      Documentation
      Find detailed information about ServiceNow products, apps, features, and releases.
      Impact
      Accelerate ROI and amplify your expertise.
      Learning
      Build skills with instructor-led and online training.
      Partner
      Grow your business with promotions, news, and marketing tools
      ServiceNow
      Learn about ServiceNow products & solutions.
      Store
      Download certified apps and integrations that complement ServiceNow.
      Support
      Manage your instances, access self-help, and get technical support.
"Next business day" calculates two business days if the start time is on weekends, holidays, or before business hours - Known Error
  • >
  • Knowledge Base
  • >
  • Known Error (Knowledge Base)
  • >
  • "Next business day" calculates two business days if the start time is on weekends, holidays, or before business hours
KB0647482

"Next business day" calculates two business days if the start time is on weekends, holidays, or before business hours


5935 Views Last updated : Jan 28, 2024 public Copy Permalink
KB Summary by Now Assist

Description

Next business day calculates two business days if the start time is on weekends, holidays, or before business hours.

Steps to Reproduce

  1. Navigate to Scripts - Background.

  2. Run the following script include.

    For more information, see the product documentation topic Using DurationCalculator to calculate a due date.

     var dc = new DurationCalculator();
    var tz = "Europe/Brussels";
    dc.setSchedule("090eecae0a0a0b260077e1dfa71da828", tz); //8-5 weekdays excluding holidays
    dc.setStartDateTime("2016-07-01 13:26:40");
    dc.calcRelativeDuration("3bfa9bd10a0a0b5200c18037fbaa9a2c"); //End of next business day
    gs.print(dc.getEndDateTime());
  3. Run the same script, but change the value of dc.setStartDateTime("");.

    The output shows unexpected relative end time. Note that July 4 in this scenario is a holiday.

    SET START TIME OUTPUT COMMENT

    dc.setStartDateTime("2016-07-01 13:26:40"); *** Script: 2016-07-05 15:00:00 This is correct
    dc.setStartDateTime("2016-07-02 13:26:40"); *** Script: 2016-07-06 15:00:00 This is not correct, expected output: 2016-07-05
    dc.setStartDateTime("2016-07-03 13:26:40"); *** Script: 2016-07-06 15:00:00 This is not correct, expected output: 2016-07-05
    dc.setStartDateTime("2016-07-04 13:26:40"); *** Script: 2016-07-06 15:00:00 This is not correct, expected output: 2016-07-05
    dc.setStartDateTime("2016-07-05 05:26:40"); *** Script: 2016-07-06 15:00:00 This is not correct, expected output: 2016-07-05, because the business time has not occured yet
    dc.setStartDateTime("2016-07-05 09:26:40"); *** Script: 2016-07-06 15:00:00 This is correct

 

 

Workaround

Create a new Relative Duration[cmn_relative_duration] in order to avoid having the calculation be two days when the current time is outside of the schedule. Use the following script:

/////// Start Script
var days = 0;   var initialStartDateTime = calculator.startDateTime;   if (calculator.schedule.isInSchedule(calculator.startDateTime)) days=1;  else // Making sure the calculation is not affected when start time is outisde the schedule but after a daily end (example, Friday 19:00).  calculator.startDateTime.add(calculator.schedule.whenNext(calculator.startDateTime, calculator.timezone));    calculator.calcRelativeDueDate(calculator.startDateTime, days, "17:00:00");    calculator.startDateTime = initialStartDateTime; /////// End Script 

 


Related Problem: PRB1032810

The world works with ServiceNow.

Sign in for more! There's more content available only to authenticated users Sign in for more!
Did this KB article help you?
Did this KB article help you?

How would you rate your Now Support digital experience?

*

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

What can we improve? Please select all that apply.

What are we doing well? Please select all that apply.

Tell us more

*

Do you expect a response from this feedback?

  • Terms and conditions
  • Privacy statement
  • GDPR
  • Cookie policy
  • © 2025 ServiceNow. All rights reserved.