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.

Schedule flow for the 1st Friday of every quarter

Brian Lancaster
Kilo Patron

I need to have a flow that triggers the first Friday of every quarter. What is the best day to do this?

1 ACCEPTED SOLUTION

Anks26
Kilo Sage

Hi Brian,

Unfortunately, this is not yet possible, however you can create a subflow and then trigger it via scheduled job. 

Please see KB0961745 for reference. 

You would run the scheduled job weekly on a Friday and check if its the first month of the quarter and then since a Friday should occur in First 7 days it should only come true once in that month. 
Your script condition  should be something like this but please test it in non-prod

var answer = false;
var now = new GlideDateTime();
var month = now.getMonth();
var day = now.getDayOfMonth();
if ((month == 1 || month == 4 || month == 7 || month == 10) && day <= 7) {
    answer = true;
}
answer;




Hope this helps

Thanks
Anks


View solution in original post

5 REPLIES 5

reddysurendra
Tera Guru

Hi Brian,

I have got similar requirement to create a task on 1st day of every quarter

Solution:
I have created a custom action with below fields and script
fields:-
Input - input_date  (date/time)
Output - monthNumber (integer)

script:-

(function execute(inputs, outputs) {
     // Convert the input_date (Date/Time) to a GlideDateTime object
    var date = new GlideDateTime(inputs.input_date);

    
// Extract the month number (0-based in GlideDateTime, so add 1)
    var monthNumber = date.getMonthUTC(); // getMonthUTC()
 
    // Populate the output field with the month number as an integer
    outputs.month_number = monthNumber;
})(inputs, outputs);


Later I have used if condition to check the month number =1,4,7,10

Regards
Reddy Surendra