Scheduled job execution on 23rd working day of every month

JPSS
Tera Contributor

How to trigger a  scheduled job on 23rd working day of all month

4 REPLIES 4

Mark Roethof
Tera Patron
Tera Patron

Hi there,

 

Would this work for you?

MarkRoethof_0-1705475836485.png

 

 

Assuming you mean Day on the month, not workday. There are not many months with 23 workdays.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Priyanka_786
Tera Guru
Tera Guru

Hi ,@JPSS 

Try below solution

To exclude holiday, use Schedule.

  1. Create a new Schedule (from Navigator, go to System Scheduler > Schedules > Schedules)
    Add "Holidays *(exclude)" as a Child Schedule. for e.g. OOB schedule-"8-5 weekdays excluding holidays"
  2. Create scheduled job with Run as daily and check Conditional checkbox.
  3. In condition box, add below script

function checkIfTwentythirdDay() {
var grSchedule = new GlideRecord('cmn_schedule');
if (grSchedule.get('name', 'Your created schedule name')) {
var sched = new GlideSchedule(grSchedule.sys_id);

var gdt = new GlideDateTime();
gdt.setValue(gs.beginningOfThisMonth());

var days = 22;
var dur = new GlideDuration(60 * 60 * 24 * 1000 * days);
var twentyThirdDay = sched.add(gdt, dur);

var today = new GlideDateTime();
today.setDisplayValue('2024-01-17 12:00:00'); // setting today's date

return (today.getDayOfMonthLocalTime() == twentyThirdDay.getDayOfMonthLocalTime());
}
return false;
}

checkIfTwentythirdDay();

 

 

 

Kindly mark my response helpful/accepted if it helps.

Regards,

Priyanka Salunke

Amit Verma
Kilo Patron
Kilo Patron

Hi @JPSS 

 

Please refer below snip. I am assuming that you want to trigger the scheduled job on 23rd of every month. If your requirement is to run this scheduled job on 23rd working day of the month, refer this post https://www.servicenow.com/community/developer-forum/schedule-job-to-run-on-every-11th-business-day-...

 

AmitVerma_0-1705477122752.png

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

sourav1999
Mega Guru

To trigger a scheduled job on the 23rd working day of all month in ServiceNow, you would need to create a scheduled job and use a script to calculate the 23rd working day of the month. Here's a step-by-step guide:

1. Navigate to System Definition > Scheduled Jobs.
2. Click New to create a new scheduled job.
3. Fill in the necessary fields such as Name, Description, and Class.
4. In the Run field, select "Periodically".
5. In the Repeat Interval field, select "Monthly".
6. In the script field, you would need to write a script that calculates the 23rd working day of the month. This script would need to take into account weekends and public holidays. Here's a basic example of how you might do this:

javascript
var today = new GlideDateTime();
var month = today.getMonth();
var year = today.getYear();
var workingDays = 0;
var day = 1;

while (workingDays < 23) {
var date = new GlideDateTime();
date.setDate(year, month, day);
var dayOfWeek = date.getDayOfWeek();
// Skip weekends
if (dayOfWeek != 1 && dayOfWeek != 7) {
workingDays++;
}
day++;
}

// The 23rd working day of the month
var targetDate = new GlideDateTime();
targetDate.setDate(year, month, day - 1);


7. Click Submit to save the scheduled job.

 

For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - nowgpt.ai