Choose only first business day of the next months
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2024 03:49 AM
Hi, guys.
I need to be able to choose just the first business day of any month ahead.
I have a Schedule of working days and I need to use it, but I don't know what can I do to be able to choose only these first working days of each next month. Could someone help me?
thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2024 10:59 AM
@SCruz Identify the start of the upcoming month (e.g., 01-December-2024).
Use the GlideSchedule API to iterate from the first day of the month and find the first valid working day.
Demo Script you can try if helps you:
function getFirstBusinessDayOfMonth(scheduleName, year, month) {
// Create a GlideDateTime object for the first day of the specified month
var firstDay = new GlideDateTime(); firstDay.setDisplayValue(`01-${month}-${year}`);
// Create a GlideSchedule object for the specified work schedule
var schedule = new GlideSchedule(scheduleName, 'sys_id', '123'); // Replace with your schedule's sys_id
// Iterate through days until a working day is found
while (!schedule.isInSchedule(firstDay)) {
firstDay.addDaysLocalTime(1);
}
// Return the first business day as a display value
return firstDay.getDisplayValue();
}
// Example:
var firstBusinessDay = getFirstBusinessDayOfMonth("Company Work Schedule", 2024, "12");
gs.info("The first business day of December 2024 is: " + firstBusinessDay);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2024 11:05 AM - edited 11-15-2024 11:07 AM
Hi @SCruz ,
You can create a new business calendar (for example, Working month) navigating Business calendar> Business calendars. Then create all 12 months entries under 'Business calendar entries' related list for upcoming years with start (as per working start date) and end of each month date. Refer to this 1st SS below.
ServiceNow document reference: Creating business calendars
Then select the 'Run' and 'Business calendar' field values in the scheduled job you created as shown in below SS.
If this address your question, please don't forget to mark this response correct by clicking on Accept as Solution and/or Kudos.
You may mark this helpful as well if it helps you.
Thanks,
Animesh Das