How to handle recurring tasks in your Bubble.io application

Dennis H. Lewis shows how to build recurring tasks in Bubble.io without manual duplication. The pro approach uses an option set for frequency, a parent task marker, and a plugin to generate future dates, then backend workflows create and delete a rolling window of task instances to keep the database clean.
Chapters
Ever need to incorporate recurring tasks into your bubble application, and we're struggling to figure out how best to accomplish this. Something as simple as do this once a week or do this every day or do this once a month seem obvious but then complicated to actually implement in the real world in your web application. Well, this video is all for you, Dennis My name is Dennis Lewis from Ratio.dev and I've been building applications since before the Internet was a thing. I was part of IBM's top secret AIX team in Austin, Texas before it ever was even a publicly available product. And after auditing hundreds of bubble applications, building many successful applications for ourselves and our customers, I realized that most developers get recurring tasks completely wrong. But here's the dirty little secret. There's actually a right way to handle this. And today I'm going to show you exactly how. Before we dive in, I want you to grab something really valuable. There's a link in the description below for our free no Code Resource center. Packed with vetted plugins, how to videos, podcast episodes, great books to read, some of them even by me. And we update it every week. It's completely free. All you need to do is put in your name and your email and you'll get immediate access. Definitely recommend that you jump over there and grab that while still at the top of your head. Now here's what happens in most bubble applications when founders try to handle recurring tasks. One is the manual nightmare. They manually create workflows over and over again. Need a task to repeat 50 times. Well, better click that copy workflow button 50 times. It's error prone. It won't work. Don't do that. And then the second possible thing I've seen is the easy trap. What they do is they take the easy way around it. They store the initial task and then they create one more. Whenever the first one is completed, they create the next one, and so on and so forth. Sounds smart, right? Wrong. Here's the problem. You can't see future tasks in your calendar view, and if somebody fails to actually mark the task as complete, then it never recurs again because that process is waiting for that action to occur and it doesn't occur. And so it's not a recurring task. That isn't really an optimal solution. I mean it's. And it's kind of half assed when that happens. People will get frustrated because they thought, oh, I thought my application was going to remind me every day to do this. And just because I happen to take Saturday off now, it forgets forever to remind Me? Well, you've dropped the ball. What's the answer? Well, I'm going to call the third option here the pro route. Now, if you need to something really quick and dirty, you can try the easy way and it'll probably get you out of an immediate problem. It's not a great solution. First, let's talk about the database. And this is where most people mess up because they don't plan the database structure and then it all kinds of falls apart. The first thing we're going to need, I'm going to jump over here into the tab. It is into the option sets tab and I'm going to create and.
Task recurring frequency. And I've created daily, every weekday, weekly, monthly, yearly and does not repeat. And I'm going to add this option into my task table. If I go here and I look at task, you'll see it repeats and I've got it set for default as does not repeat. Okay. Normally most tasks aren't repeating, they aren't recurring. When the user changes this, then I'm going to change this value here. I'm going to keep track of the parent task, the first one that was marked as recurring or repeating. Okay, I've created a repeating parent and it's just another task. I'm going to keep it a date which is repeats until could be a marker because I want it to repeat every day until the end of the month and then stop. I can set that date the last time that it happened so I can keep track of how many of them have occurred in the last one. That's going to make our workflows a little bit easier to take care of. Now let's look at the workflows. Trust me, this is going to probably blow your mind if you've never seen it before. The first thing we're going to need to do is we're going to go to our plugins and you're going to install a plugin called 1T List of Dates. All it does is it creates a list of dates for us. And I'm going to jump in here to task card and I have in here a pop up. And this is where I have this field where I can set the type of repeating. I have the date repeats until if I want, I have in here is an element called list of dates. And I've called this list of dates action items, recurring future. And this is the one in the pop up because I have another one in the card if I need it. What I've done is it starts at a specific date and I can give it, tell it how many of them I want. And I want it to report, to repeat every day. And if I look here, I can say every day, every week, every month, or every year. I want it to go one by one. So want to. Because I could do every other day if I want, or I could do every three days if I want. You can, you can make as many different things as you want, and by default it's taking the first one a day for the next 60 days. My thoughts here are I don't want to load into my database an infinite number of tasks, okay? But I want to give the user visibility for the foreseeable future. If it's in repeats every day, then I'm going to recreate these tasks for the next 60 days. Okay, now that I have a conditional on here which says that if it is weekly, then I'm going to create 52 of them and I'm going to do it one per week. Okay? I'm going to create one a week for the next year. Okay, that's long range out there. If it is weekday, then I'm going to have it skip day zero and day six, which is Sunday and Saturday. I'm excluding Sunday and Saturday, and it will do all of the weekdays. I'll keep 60 of them in there. If it is monthly, then I'm just going to create 12 of them, one every month. And if it is yearly, I'm going to create for the next five years, one a year. Okay, that gives me enough that I'm pretty sure that nobody's going to go looking out and say, oh, it doesn't six years from now. It's not in the calendar. Okay? It's not. There has to be a limit, otherwise it would be an infinite number of tasks in the database. Once we've done that, now we need to look at the creation workflow and how this all works. We've got this. This just creates a list of dates. Let's jump into the workflows tab and I'm going to go to the backend workflows here. And we have one here, which is action items create recurring items. And this takes a parent task and it takes a list of dates. Okay, and what this is going to do is it's going to create a new task, copying all the information from the original except for the parent. It's a recursive workflow. It's going to create the first one, it's going to make a change to it in the parent to make sure that we keep track of the last one created and then it's going to reschedule itself. And so it's just going to recurring go out through that list of dates and create all of the future tasks. Okay, now one thing that is going to happen is that when I mark a task completed, what I will do is I will recalculate the list of dates. So if it were 60, I had already created 60 of them. Well, it will look at how far along on the list we are and it will create as many as it needs to to get to 60 again. So it will keep creating future ones as I mark them as complete. And this is happening in a reusable element project workflows. And here we have complete item. And what it will do is it will trigger recurring. If it's repeating and the dates count is bigger than one, so it's passed in a list of dates with more than one, then what it will do is it will go through here and create the additional ones. And this will prolong this. So basically you start off with the next 60 days of a task that repeats every day. And as you complete them, then it will keep making sure you're getting to 60. There's always 60 in the future. And so that way they're always showing up in the future on your calendar. And it also doesn't overload the database with a gazillion of them because you don't really want that many in there anyway. And if you're deleting one, you need to ask if they want to delete all the future ones. If they do, we've created a backend workflow also here. That is delete future recurring items. And all it will do is it'll take all of the ones that have the same parent whose date is bigger than current date. We'll delete them so that that's how you clear out the future. And you can also do the same thing similar for if it's a modification, if you want it to check in and you change something in the parent and you want it to propagate out, you could do another one where it takes that list and just makes that change all the way down the road. So be careful to use backend workflows because this is creating a lot of data in the backend. You don't want your user interface to be bogged down while this is happening. Be careful that you use custom events if you need things to go in order inside those workflows, otherwise it could get all discombobulated. Don't forget about time zones. Usually most of your users are more or less in the same time zone or similar same country in the US and it's not a real big deal. But just keep that in mind, especially if you're going to have processes that work in a backend workflow that isn't necessarily it's not connected to a user's browser and so it will always default to utc. So if it's creating things, if you're time sensitive, it's just dates, it doesn't really matter probably. But if it's time sensitive and you've got the whole timestamp, you're being careful there. Then do be careful about your time zones. You will probably want to also have some sort of a cleanup process where you could go through and get rid of recurring tasks that haven't been used or or that were left undone in the past and there's no more of them because nobody stopped completing them until they stopped creating new ones. Then you might want to do some cleanup processes there and hopefully this will give you a pretty clear idea on how to set this up in your bubble application. If you have doub, leave me questions in the comments below. Or feel free to reach out to us here@ratio.dev and we will gladly jump on a call and try to help you out. Or if you need more help putting this into your bubble application, then we can definitely help you there as well. If you've enjoyed this video, give it a thumbs up. If you want to make us really happy, you could subscribe to our channel. That would just make this big tennis smile go across his face. If you've enjoyed this video, stick around for the next one. There'll be more soon. See you then.
More from Dennis

Is Google Killing Websites? The Future of Search, SEO & Web Design After Google I/O

Something we're still looking forward to in Bubble: richer design experiences! #bubble #nocode #ai

Big mistake companies are making right now: firing employees instead of empowering them. #ai







