sachinbhasin11
Tera Guru
Tera Guru

I was requested by a customer recently to calculate the due date for a case which was let's say X business days from the date of create/update etc.,

Now we know that setting a due date can be a challenging task due to a lot of moving parts, such as scenarios involving e.g. Holidays, non-business hours, Out of office hours, etc. leading up to a lot of coding and maintenance too

Due date may have several dependencies too e.g. SLA timeline, dashboard, actions, etc. hence it's not wrong to say that it can play a very critical part to drive the overall workflow

Thanks to the GlideDuration API, we can now easily calculate the due date on a record in line with our schedules. Infact, there are sample scripts provided at the link below which you can copy-paste in your BR, Flow, workflow to calculate the due date

https://docs.servicenow.com/bundle/sandiego-application-development/page/script/server-scripting/con...

You can calculate relative durations too...Relative duration is very similar to simple duration except a piece of script is used to determine what parts of a day to remove from the difference calculation.

This script is stored in table cmn_relative_duration and can be examined by navigating to System Scheduler > Schedules > Relative Durations. There are some example relative duration scripts in the out-of-the-box instance.

Hope this article helps you and makes your life easy when it comes to date calculations, as we can certainly re-use this logic not just for due date but other use cases too

Comments
Community Alums
Not applicable

Quick note, the URL Sachin gives above has been changed to:

https://docs.servicenow.com/bundle/rome-application-development/page/script/server-scripting/concept/c_DrtnClDueDate.html#c_DrtnClDueDate

Version history
Last update:
‎10-10-2021 11:34 PM
Updated by: