Scheduled job

rahul122
Tera Contributor

How do i run a scheduled job quarterly on 1st,20th,30th of each till now i worked on this code this seems not be working :

 

(function() {
var today = new GlideDateTime();
var day = today.getDayOfMonth(); 
var month = today.getMonthUTC(); 


if ((day == 1 || day == 10 || day == 20) && (month == 0 || month == 3 || month == 6 || month == 9)) {
var templates = new StdChangeUtils().getNotUsedTemplates(gs.getProperty('change.std.months_before'));
if (templates.length > 0) {
gs.eventQueue('change_form_inactivity', null, templates.toString(), '');
}
}
})();

5 REPLIES 5

Sandeep Rajput
Tera Patron
Tera Patron

@rahul122 The code seems fine, please check if your scheduled job is scheduled to run daily. 

yes @Sandeep Rajput  it is scheduled to run daily 

Then ideally it should trigger notifications on every first, 20th and 30th day when month is Jan, March, June or September.

HrishabhKumar
Kilo Sage

Hi @rahul122 ,

Your current script logic has a small error: it checks for day 10 instead of day 30. Here's a revised version of your script:

(function() {
    var today = new GlideDateTime();
    var day = today.getDayOfMonth(); 
    var month = today.getMonthUTC(); 

    if ((day == 1 || day == 20 || day == 30) && (month == 0 || month == 3 || month == 6 || month == 9)) {
        var templates = new StdChangeUtils().getNotUsedTemplates(gs.getProperty('change.std.months_before'));
        if (templates.length > 0) {
            gs.eventQueue('change_form_inactivity', null, templates.toString(), '');
        }
    }
})();

 

Thanks.

Hope it helps.

Mark it helpful and accept solution if my response turns useful.