Hi. I have a things in database with dates in fields type Date. I want when this dates not actuality anymore it automatically to delete. I have a button and need to click it all things with date early current date. How I need to set workflows? Thanks
I think for any repeating/automatic task backend workflow is the solution. Hope who are experienced in this will come up with a silution
Hey there!
@kazimdgoni has the right of it, youâll need to set up a recurring backend workflow to manage this task for you. Probably set to run once per day.
However, Bubbleâs own âRecurring Workflowâ has a rather unfortunate limitation for users not on the higher tier plans (Professional+) in the fact that they canât set recurring workflows to be run very often. Professional or higher is needed for Weekly runs and Production or higher is needed for Daily.
Hope is not lost, however, as you can âcheatâ the system and make your own. What youâll need to do is set up a backend API workflow, weâll trigger this for the first time with a button and from that point onwards it will automatically schedule itself each day
The first step, if you donât already have Backend Workflows enabled would be to turn them on. This is easily done through the API tab of your apps settings
Once this is taken care of, âBackend Workflowsâ will appear at the very bottom of the page list in the top left of your screen.
Now that weâve got backend workflows up and running, the next step is to create the workflow. This will handle deleting the items that are past their date and then schedule itself again.
Youâll want to create a new API workflow and name it appropriately. In this case, Iâve gone with âdaily_triggerâ.
Inside this workflow, weâll want to add two actions. One to delete the list of items and the other to schedule itself.
Deleting the list of items is easy enough, you just need to use the Bubble function âDelete a list of itemsâ and set it up to do a search for all items where âDate < Current Date/Timeâ. As I donât know what your database item is called, Iâm using a mock one called âEventâ
The second action weâll want to set up is âschedulingâ itself for the next day. This step uses the âschedule API workflowâ action, selecting âdaily_triggerâ as the chosen workflow. Weâll then tell it to take the âCurrent Date/Timeâ, add one day to it (to make it tomorrow) and then set the hours, minutes and seconds to 0.
The reason for doing this is because Bubble will schedule this after deleting the list of items. Setting all the time fields to 0 gets Bubble to schedule this for exactly midnight, whereas if we just do +(days):1, it would slowly end up later and later.
Imagine it takes 1 minute to delete the list every time, if we didnât âresetâ the timer to midnight, it would run at 00:01, then 00:02 and after several months itâd be over an hour in the future.
You can naturally change this âset time to 0â to any time of the day you like, though.
Once this is done, all weâll need to do it copy this âscheduleâ action and paste it onto any button you have.
You only need to click this button one time, and it will get this workflow going permanently. You can freely make changes to these workflows and any updates will apply the next time it runs.
Please note that if youâve got a Development and a Live version of your Bubble app, youâll need to click it once on each environment, as you cannot schedule Live version items from Development and vice versa.
I hope this helps! Please let me know if you have any questions or queries
Kind Regards,
Joseph @ millionlabs.co.uk
Thank you so mush for your detailed instructions. But I have a things in database not as list of things. Can I set the same workflow in this case?
@bluesun440 Thatâs the benefit of this method, it goes through your database and will delete all items in the list of things that meet the criteria.
I see youâve named your database item âTimesâ. Youâll want to set up the âlist to deleteâ field as âDo a search forâŚâ and select âTimesâ.
Then, inside the search, youâll want to set it up to only delete items where âdate < current date/time.â
This entire system is designed to be automatic. Youâll trigger the button once and then never need to do so again, every day at midnight it will delete all âTimesâ that are now in the past.
Kind Regards,
Joseph @ millionlabs.co.uk
Hello @bluesun440 ,
First, you have to create a workflow on page load and create an event for deleting the data from the database.
Set a condition for the event if the data date is < current date/time then data will be deleted. If it is greater than the current date/time then the event will not run.
If any further assistance is required get in touch with me on:
LinkedIn:- https://www.linkedin.com/in/karamjitsinghwaldi
Gmail:- karamwise@gmail.com
wow! itâs works, thank you!
thank you!
I have another one question: this flow is working, clear all dates early current date, but including current date. How I can to delete all exept today?
@Joseph-Harris Wow. That was great. I also learned a lot. I was always confused about recurring and scheduling workflow in the backend. It helped me a lot too.
There are very few details about backend workflow and very few of those are clearly saying anything that might help the beginners like me.
Thank you very much. I highly appreciate your effort.
If youâre running it on a front-end button (looks to be the case from your screenshot), the âcurrent date/timeâ function will be deleting any âthingâ that has the date set before the current date. For instance, you have a record set as 27th January 8:00am and you run the function on 27th January 10:00 am, it will see that item as being âin the pastâ and delete it.
At least, this is what I reckon is the problem youâre facing from the context.
To avoid this, you could always use the âset hours to 0â function and then the âset minutes to 0â function after âCurrent Date/Timeâ, much like I did for running the recursive workflow in the backend example! This will make sure it only deletes items from before today
Hope this helps!
Kind Regards,
Joseph @ millionlabs.co.uk
Amazing! Thanks for your help!
This topic was automatically closed after 70 days. New replies are no longer allowed.