Schedule jobs but for specified time how we achieved this

1dusjhyahnt
Tera Contributor

 

I need to schedule a recurring task assigned to Zenpact Group

 

The task should be created once every three months, beginning the first Tuesday every January, April, July and October (or you can think of something better if it is more suitable to you).

 

How we achieved this for this time 

1 ACCEPTED SOLUTION

Set your scheduled job to run this script on a daily base. It will create the task only on the defined days.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

View solution in original post

3 REPLIES 3

Mark Manders
Mega Patron

This script creates an incident, but I guess your question is more about how to get the timing of the trigger correctly:

(function executeRule(current, previous /*null when async*/) {
    // Get current date
    var currentDate = new GlideDateTime();
    currentDate.setDayOfMonth(1); // Set day to the 1st of the month

    // Check if it's January, April, July, or October
    var month = currentDate.getMonth();
    if (month == 0 || month == 3 || month == 6 || month == 9) {
        // Check if it's the first Tuesday of the month
        if (currentDate.getDayOfWeek() == 3) { // 3 corresponds to Tuesday
            // Create incident here
            var newIncident = new GlideRecord('incident');
            newIncident.initialize(); // Initialize the record
            // Set other incident fields as needed
            newIncident.insert(); // Insert the record
        }
    }
})(current, previous);

Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Hi Mark,

 

Where i will use this script , means i will use this script with scheduled jobs or individual or what condition i will use in business rule ?

Set your scheduled job to run this script on a daily base. It will create the task only on the defined days.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark