Choose only first business day of the next months

SCruz
Mega Contributor

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!

2 REPLIES 2

Abhay Kumar1
Giga Sage

@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);

Animesh Das2
Mega Sage

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 

AnimeshDas2_0-1731697228509.png

Then select the 'Run' and 'Business calendar' field values in the scheduled job you created as shown in below SS.

AnimeshDas2_1-1731697481500.png

 

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