How to Schedule a Celigo Flow on the Last or Second Last Business Day of the Month

Hi Everyone,

Need some guidance on how to schedule a Celigo flow to run on either the last business day or the second last business day of every month. Has anyone implemented this before? Open for suggestions.

Thanks in advance

Hi @vishnuagarwal349 ,

If your export is set up to pull all records on every run, you can achieve the last business day cadence using a workaround.

In the cron job, select the day of the month and choose 26,27,28, 29, 30, and 31. The reason for this range is that the last business day of any month will always fall within these last 6 days. Then, in the flow itself, use a preSavePage script to check whether it's actually the last business day of the month, and only proceed if that condition is met.

After exporting records, I’d also recommend adding a step to mark the records as exported (e.g., via an import back to source application), so they don’t get pulled again the next time the flow runs.

For the last business day, here’s the preSavePage script:

import dayjs from 'dayjs';

function preSavePage(options) {
  const now = dayjs(options.job.parentJob.startedAt);
  const endOfMonth = now.endOf('month');

  let lastBusinessDay = endOfMonth;
  while (lastBusinessDay.day() === 0 || lastBusinessDay.day() === 6) {
    lastBusinessDay = lastBusinessDay.subtract(1, 'day');
  }

  if (now.date() !== lastBusinessDay.date()) {
    return { data: [], errors: [], abort: false, newErrorsAndRetryData: [] };
  }

  return { data: options.data, errors: options.errors, abort: false, newErrorsAndRetryData: [] };
}

For the second-to-last business day, adjust the script to step back one additional business day after finding the last.

Also, check out @tylerlamparter's comment here — it might be helpful: https://connective.celigo.com/t/set-flow-schedule-to-every-2-weeks/4544/7

Hope this helps!