Hi guys,
i am looking to run an automation only one time, is that possible?
Let say i have an event and i want to send info one time on 15.5.24 and than stop.
At the moment i am thinking of running a task each day and only run it if the day is 15.5.24.
Is there a better way to do that to create one time automation?
Hereās what I would do, let me know if this works for you.
Add a DateHelper. Use the Get current Date function I used YYYY-MM-DD and my local timezone.
Add a Code Piece.
Add key ācurrentDateā and variable pass through for the value from DateHelper.
Click on fullscreen to expand the code screen.
Click āadd npmpackageā and add the package below as a dependency.
date-fns
Add this code into the code body:
import { isSameDay, parseISO } from 'date-fns';
export const code = async (inputs: any): Promise<boolean> => {
// If inputs.currentDate is provided and is a valid date, use it.
// Otherwise, use the current system date.
const currentDate = inputs?.currentDate ? new Date(inputs.currentDate) : new Date();
// Define the target date as a string and parse it to a Date object
const targetDateString = '2024-05-11';
const targetDate = parseISO(targetDateString);
// Check if the current date is the same day as the target date
return isSameDay(currentDate, targetDate);
};
Add a branch for True/False. If true, execute your automation. If False, do whatever you want.
I would certainly test this before the date in question to ensure it is working the way you want.
What I would do is ask ChatGPT for a cron expression on your date and use that for the schedule piece, here is the answer:
To create a cron expression that runs only on May 15, 2024, you can set it up to trigger at a specific time of day. For example, if you want it to run at 8:00 AM on that date, the cron expression would be:
0 8 15 5 ? 2024
Hereās how the expression breaks down:
The first 0 stands for the minute (0 minutes past the hour).
The 8 stands for the hour (8 AM).
The 15 stands for the day of the month (15th).
The 5 stands for the month (May).
The ? is used in the day-of-week field to denote no specific value (since day of the month is already specified).
The 2024 stands for the year.
This expression will ensure the task runs at 8:00 AM on May 15, 2024, and not on any other date or time. If you need it to run at a different time, adjust the hour and minute fields accordingly.