I’m looking to save user data once per month, but not on an exact monthly basis.
The user is able to select the Last Sales Day for each month, which is typically 4-8 days before the calendar end of the month. I’m looking to run a recurring workflow that executes at 11:59pm on that Last Sales Day.
Since the Last Sales Days month to month are likely not on the same numeric day of the month, or spaced evenly apart, I’m unsure how to set this up with a recurring workflow.
Right now the way I have that Last Sales Day input set up is the User selects the Year from a dropdown, and then fields for all 12 months either populate with pre-set data for the last calendar day of each month or data the user has overwritten with their Last Sales Day for that year. The user can change the field for each month to be their Last Sales Day if it differs from the last calendar day, and then press a save button to save the data to a Data Type.
How do I structure a recurring workflow to trigger my backend workflow which saves the data at 11:59pm on that Last Sales Day?
Thanks,
Raptorflapjacks
Hey that is a tricky one on first glance.
Here is how I would approach it. This won’t be perfect but the intention is to spur on some ideas.
First, I would add the year as a field on the data type with all the months so that it’s 2025 and then all the dates to run for each of the 12 months.
When it’s first triggered to run, i.e. a user signs up Feb 8th 2025, it will run on whatever date of that month. Then after everything has ran, run a backend workflow that sets up the next one to run based on a conditional that looks at what month that will be.
So personally I wouldn’t get fancy, I would have 12 actions in a row which all run the thing that gets run every month and in each action I would put a conditional for when the current month + 1’s value for month is equal to the month of the date. (Note this is also where I would use the year’s value, to see if we use the 2025 set of 12 dates, or the 2026 one… or, forget the idea of adding the year and update the 12 dates afresh every year — again not aiming for perfection but hopefully moves things forward.)
I’m realizing this is a challenge to explain so likely also to understand so here is a final example — user signs up Feb 8, and during signup a thing is set to run on last sales day of Feb 26. Let’s say that the next two months’ dates are March 30 and April 28. At the end of the Feb 26 workflow run, you go through the 12 action workflow where it’s looking for which action will be for next month. The 3rd action (in the list of 12) is the correct one that instructs it to run the whole thing again on March 30 and that’s the one you want to make sure your conditional of today’s month (Feb) plus one month (March) is equal to the month that is in the 3rd date in your list of 12 dates, aka March in this case. The 11 other ones won’t fire because they are not current month + 1, i.e. March.
Then when March 30 roles around the whole thing is done again but this time the month + 1 going to be April so it will do the April 28 date of this example.
The last consideration is how long it takes to run workflows, because is you’re running things at 11:59pm on the last actual day of a month and it takes 5 mins to run all of your stuff you’ll be in the next month which will throw it off. Hope that helps and follow no code academy on YouTube if you want other brainy bubble tips.
Hey man,
Thanks for this awesome help!
Right now my Data Type is set up like this, where the Year field pulls from an Option Set list of years, so I think I’m on the right track.
I love that idea you have of keeping it simple and creating a line of code for each month, and also being aware of the time the workflow is run. I might bump it back to 11:45pm on that day, although I don’t expect the workflow to take that long to run.
In this industry, next year’s Last Selling Day is known typically by Q4 of the prior year, so I’ll be sure to create an alert to update this around the end of the calendar year.
No Code Academy on Youtube is fantastic! I’ve watched your videos before, but I just made sure I’m subscribed! Thanks again man, and Merry Christmas to you and your family.
Raptorflapjacks
1 Like
Maybe i am not understanding it, but 12 action in a row make things complicated.
Is is user have different on different month, like 30 days for JAN but for FAB its 31 days, if so then its we need t collect the number of days for each seperatly and only do a condition on same workflwo to pass the correct days.
if if number of days are same for each cycle and only the last day can vary, then we can ask user to give a number of day for his monthly cycle and just user that number of days on next trigger.
Hmm, here’s another way of saying it – you have a main workflow that runs at the end of every month. At the end of that workflow, in order to set up the following month to run on the correct date, you create 12 actions which will run that main workflow on the special date for each of the 12 months in the calendar year.
Again, to spell it out in detail – for action 1, you program the main workflow to run on the pre-chosen date in Jan. In action 2, you program the main workflow to run on the pre-chosen date in Feb. In action 3, you program the main workflow to run on the pre-chosen date in March. And so on.
Then you’ll have a conditional on each action, 12 total. The 12 conditionals are:
Action 1 conditional: If current month + 1’s month value = January
Action 2 conditional: If current month + 1’s month value = February
Action 3 conditional: If current month + 1’s month value = March
Action 4 conditional: If current month + 1’s month value = April
etc…
The format for the part before the = sign is
So this is saying then when the next month is January, we’ll run the January action (which assumes you’ve put the special date in January into Action 1).
The full conditional statement would look like the below and you’ll manually enter January, February, March, April, etc in place of the word “January” below:
Does that help?
1 Like
I prefer a non-daisy chaining approach…
If a workflow fails for some reason or you happen to break the chain somewhere (clear the workflows during debugging) then the chain is broken and will go unnoticed. you also have no visibility on it.
I would create a data type for “workflow” and when the user saves the data for the dates I’d create it as workflow data. This would achieve a few things.
- users have greater flexibility in that they could trigger on multiple days in a month.
- you could allow the user to customize the logic to trigger quarterly/yearly or on same date each month
- you could give users the ability to see upcoming workflows and cancel them or edit them (or you could hide this and just clear and reset them on user submit)
- the system now has a log of these workflows running (better than bubbles logs)
then I’d set a daily check event in the backend to search for workflows that are due to run on the current date and process them for all users.
you would need to consider issues with ramping - having thousands of users that want to process on the same date and time could pose issues. You could schedule the workflows out better using api on list with a specific iteration interval.
I’d also hold a status on the workflow data for success/fail and maybe a few counts for records processed.
You could also then trigger an email based on the workflow status changing. And you could link the report (or whatever you’re doing) back to the workflow for future audit purposes.
1 Like
but sir why we this much action, cant we simple search or link the related much number with and and pass it as parameter into api workflwo and simply referenc it. ?
if i was doing it i would definaltly tiried to do that, because it make the app less comples and easy to manage.