Start date must be 10 working days ahead in catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2023 02:49 AM
Hi,
I need to set a limitation on the date that will work: start date must be 10 working days ahead.
Example. If I raise a new starter form on 11th December 2023, I cannot enter a start date of the 15th. Start date must be the 25th December at the earliest.
Any ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2023 02:57 AM
HI @New user1212 ,
I trust you are doing great.
You can create a BR to add this validation as given below code
(function executeRule(current, previous /*null when async*/) {
var minStartDate = calculateMinStartDate();
if (current.start_date < minStartDate) {
current.setAbortAction(true);
gs.addErrorMessage("Start date must be at least 10 working days from today. The earliest possible date is " + minStartDate);
}
function calculateMinStartDate() {
var today = new GlideDateTime();
var workingDaysToAdd = 10;
var totalDaysToAdd = 0;
while (workingDaysToAdd > 0) {
totalDaysToAdd++;
var tempDate = new GlideDateTime(today);
tempDate.addDays(totalDaysToAdd);
var dayOfWeek = tempDate.getDayOfWeekUTC();
if (dayOfWeek !== 0 && dayOfWeek !== 6) { // 0 = Sunday,
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2023 03:44 AM - edited ‎11-15-2023 04:14 AM
and what if I want it to be set to only one variable in the catalog item?
I want the date in the catalog item to have this limitation: As the policy states an SLA of 10 working days, I think we should try and see if we can do it that way, so the start date must be 10 working days ahead.
Example. If I raise a new starter form on 11th December 2023, I cannot enter a start date of the 15th. Start date must be the 25th December at the earliest.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2023 03:10 AM
what do you mean by working days?
You can use schedule which considers holidays as well
what script did you start with?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader