The CreatorCon Call for Content is officially open! Get started here.

How to add business days to a date field based on category selection (skip weekends)?

rah dev
Tera Contributor

Hello Community,

I need help creating an OnChange client script that adds business days to a date field based on a category selection, while skipping weekends (Saturday and Sunday).

Requirements:

  • When category = "Hardware" → Add 5 business days to the date field
  • When category = "Software" → Add 10 business days to the date field
  • Weekends (Saturday and Sunday) should be excluded from the count
  • Date field name: u_date

What I've tried: I've attempted using GlideDateTime() with addDaysLocalTime(), but I'm not sure how to properly implement the weekend-skipping logic and ensure only business days are counted.

1 REPLY 1

Bhuvan
Mega Patron

@rah dev 

 

Refer below links for the requirement

 

https://www.servicenow.com/community/developer-articles/validating-the-from-date-and-to-date-and-exc...

 

https://www.servicenow.com/community/developer-articles/add-business-days/ta-p/2324391

 

If this helped to answer your query, please mark it helpful & accept the solution. 

 

Thanks,

Bhuvan