How to exclude weekends (Saturday and Sunday) in Normal change Planned Start Date

Dhanu1
Tera Contributor

Hi Team,

 

I have requirement to exclude Saturday and Sunday for normal change Planned start date

 

note: "working days" means Mon-Friday (excluding weekends). We want requesters to at least submit their changes with the following notice. It should apply to Planned start date (no need to restrict the time).
Normal 7 working days 

Thank you in advance

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@Dhanu1 

you can use before insert/update BR and check the day of week for planned start date

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var gdt = new GlideDateTime(current.start_date);
	var dayOfWeek = gdt.getDayOfWeekLocalTime();
	
	if(dayOfWeek == 6 || dayOfWeek == 7){
		gs.addErrorMessage("Not allowed to select weekend");
		current.setAbortAction(true);
	}

})(current, previous);

OR

you can also have onChange client script on Planned start date field and check if it's a weekend using GlideAjax

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

@Dhanu1 

Hope you are doing good.

Did my reply answer your question?

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

@Dhanu1 

Thank you for marking my response as helpful.

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

Dhanu1
Tera Contributor

Hi Ankur,

Thanks for your reply 
sorry for the confusion my requirement is Planned start date is 5 working days , user able to select upto 5 working days today(13/04/2023) to (19/04/2023) but it is counting Saturday and Sunday also.
Thanks in advance .