Flow need to wait everymonth on particluar date

nandini29
Tera Expert

Hi All

There is scenario where after flow is triggered, flow should wait untill 25th of everymonth, How we can achieve this in flow designer?
Could someone provide response on this?Thanks in advance

Thanks,
Nandini

5 REPLIES 5

Dr Atul G- LNG
Tera Patron

Hi @nandini29 

 

https://www.servicenow.com/community/servicenow-ai-platform-articles/flow-designer-making-the-flow-w...

 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0958902

 

****************************************************************************************

Regards

Dr. Atul G. - Learn N Grow Together ServiceNow Techno - Functional Trainer

LinkedIn: https://www.linkedin.com/in/dratulgrover

YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG

******************************************************************************************

Ehab Pilloor
Mega Sage

Hi @nandini29,

Have a script in a Flow Variable to fetch 25th of very month and return the date.

var now = new GlideDateTime();
var target = new GlideDateTime();

// Set target to the 25th of the current month
target.setDayOfMonth(25);

// If the 25th has already passed, move to next month
if (target.compareTo(now) <= 0) {
    target.addMonthsLocalTime(1);
    target.setDayOfMonth(25);
}

return target.getValue();

Use the wait-for-duration activity, change the duration type to relative duration, and then used 1 second after the flow variable value to make the flow until the specified time and then triggered the next action. 

EhabPilloor_0-1786530087958.png

 

Its best if you trigger Flow from Scheduled Job which has low code setting for running on 25th of every month.

 

 

Please Accept this response as Solution if it assisted you with your question & Mark this response as Helpful.

 

Kind Regards,

Ehab Pilloor

HarishKumar6668
Tera Guru

Hi @nandini29 ,

Could you clarify whether you want the flow to execute repeatedly on the 25th of every month after it is triggered, or whether it should wait until the next upcoming 25th of the month after the flow is triggered i.e execute only once?

Thanks,
Harish

yashkamde
Giga Sage

Hello @nandini29 ,

 

You can achieve this using 2 flows :

 

Flow A : Initial Trigger - (your current trigger.. record created, catalog item, etc.)

> Then add a Script step to calculate the next 25th and schedule a resume event:

(function execute(inputs, outputs) {
    var gdt = new GlideDateTime();
    var day = gdt.getDayOfMonthLocalTime();
    
    // If today is past the 25th, roll to next month's 25th
    if (day >= 25) {
        gdt.addMonthsLocalTime(1);
    }
    
    var target = new GlideDateTime(gdt);
    target.setValue(gdt.getByFormat("yyyy-MM") + "-25 00:00:00");
    
    // Schedule an event to fire exactly at the target date/time
    gs.eventQueueScheduled(
        'event_name',   // event name
        current,                                     // record (pass your trigger record)
        current.sys_id,
        '',
        target
    );
    
    outputs.scheduled_for = target.getDisplayValue();
})(inputs, outputs);

 

Flow B : Resume on 25th Trigger:

> Created by Event - event name 'event_name'

 

If my response helped mark as helpful and accept the solution.