Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to create scheduled job on last Friday of the month

Robert T
Tera Contributor

HI SN folks,

I've posted this in developer community because from what I can tell this will take a script one way or another.

I need to create either a scheduled job or a Flow Designer trigger that executes an incident record creation on the last Friday of every month at 7am.

In both the scheduled job builder and in Flow Designer, it appears I can target a date of the month or a day of the week, but not something as dynamic as the last Friday of the month.  The scheduled job builder allows for the "Conditional" check-box, which then accepts a glide script (I think).  

Any help from here would be greatly appreciated.

Thanks!

--Robert

1 ACCEPTED SOLUTION

Saurav11
Kilo Patron
Kilo Patron

Please check the below thread has the same requirement as you

https://community.servicenow.com/community?id=community_question&sys_id=5cfd4368db79f3801cd8a345ca961916

Please mark answer correct/helpful based on impact

View solution in original post

2 REPLIES 2

Saurav11
Kilo Patron
Kilo Patron

Please check the below thread has the same requirement as you

https://community.servicenow.com/community?id=community_question&sys_id=5cfd4368db79f3801cd8a345ca961916

Please mark answer correct/helpful based on impact

vkachineni
Kilo Sage

Basing on the other reply

function isFridayOfLastWeekOfMonth() {
    var report_date = new GlideDateTime();
    var day_in_week = report_date.getDayOfWeekUTC();
    //gs.print(day_in_week); //1-Monday
    var days_in_month = report_date.getDaysInMonthUTC();
    //gs.print(days_in_month);
    var day_of_month = report_date.getDayOfMonthUTC();
    //gs.print(day_of_month);
    if (day_of_month >= days_in_month - 6) {
        if (day_in_week == 5) {
            //It's Friday of last week of the month.
            return true;
        } else {
            return false;
        }

    } else {
        return false;
    }
}
isFridayOfLastWeekOfMonth();

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022