Schedule a recurring event on a specific day per specific group of users

Hello,

I’m trying to set up a weekly outbound email scheduled on a specific day (e.g. send out an email every Tuesday at 9am). And that email only sends out to a selected group of users.

I have used Option Sets to allow users to select a desirable day and time. Then I’m searching how to move forward.

I thought I could set up the timing by using ‘arbitrary date/time’ to define the first date then add +7. But it seems it’s not possible to use any dynamic data in an arbitrary date/time field.

Also, as I want to schedule per group, and my app supposed to have many different groups who have their own custom schedule. I discovered that Bubble has restrictions on scheduling recurring events per thing. Even when I upgrade to a professional plan, it allows up to 5 recurring events per thing.

How to address this issue? Creating a new dataset (thing) per unique group shouldn’t be the way.
Then one recurring workflow should have a dynamic date parameter…

I’m just beginning to set up this scheduling functionality. Your direction will help a lot!

Thanks!
Ohyoon

@ohyoonkwn - I think there is an easy way to do this. On the group that you are scheduling the email for, add a text field to capture the API call id. Then in the workflow to send the email, one of the last actions should be to Schedule an API Workflow. Select Current Date/Time +days:7 and use the change hour to and change minute to functions to set 9AM. After you have scheduled this workflow, make a change to the group to update the API Call Id field with the result of the previous step. This will allow you to cancel it if you need to make changes.

By doing it this way, when an email is sent on Tuesday at 9AM, it is scheduling the workflow to run again in a week and send the email again. You can make this dynamic by capturing the email times like day of the week and time of the day to make it dynamic as well. Just save all the components to the group and then reference them when scheduling the API call.

It’s actually very easy. Each day represents a number, so you need to specify which day by number from 0 to 6, monday represents 0 and sunday is 6.

You can schedule emails on each day it represents the number and pass on the users as a list to it.

Within each scheduled workflow you would need to schedule the next day(number) and so on. You can’t easily schedule for multiple days, months or years ahead without breaking your app :smiley:

p.s. for your option sets just put in from monday to sunday and extract the numbers by day to schedule the next email date.

For scheduling, look into recursive workflows.

Thanks for your answer @jdiaz! Let me try to understand what you’re saying :slight_smile:

  1. In order to set a specific weekday, shouldn’t I set that weekday instead of Current Date/Time?
  1. I don’t understand the reason why storing API call id in the target group. Will each routine generate a different API id?

I didn’t know that day represent a number! Is time also just represented as number? Or it’s date?

How can I correctly express ‘Scheduled Date’ dynamically? I would need to define it as weekday + time.

Here, as you suggested, I use Option set to declare days as number. Then how to express time?

@ohyoonkwn,

  1. For the very first workflow, you will need to specify the weekday, date and time to send the first email. Then, the first time that email is sent, the workflow that triggers the email also schedules the email for the following week. For that email to be scheduled, you would then just have to do current date/time +days 7 because it will be scheduled on the weekday already. I would just change the hour and minutes to reflect the time you want. I hope that makes sense.

  2. Storing the API call id is important because it allows you to edit the schedule. By saving the id, when the group decides that they no longer want to receive an email on Tuesdays, but Fridays instead, you can cancel the scheduled API workflow that triggers the email on Tuesday and then reschedule the email for Friday. It’s a best practice to save the API Workflow ID when you are scheduling actions in the future.

What i said in the answer number one would apply to the screenshot you posted. Since you would have sent the email on Tuesday at 9AM already, you just need to put the scheduled date as the following:

Current Date/Time +days 7 change hour to 9 change minutes to 0.

The only time you need to be dynamic about scheduling when the email is going to be sent is when it is being scheduled for the first time.

1 Like

Thanks @jdiaz I think I got the concept…

So my first workflow would be the one triggered by the frontend element right? That needs to specify the exact date and time. Also stores the API ID. Here, I’m still not able to put the exact date in the scheduled date field.

I’ve captured a desirable day/time as:

Weekday = option set expressed as number. (Monday = 0, Tue=1 …)
Hours = option set expressed as a number (8am = 8, 9am = 9 … 5pm = 17)

Then, in order to send out the very first email, the scheduled date should have all the date properties. It looks like the format should be: weekday, date, month, year, time, timezone.

Let say a user sets up the schedule as every Tuesday 9am and the time he sets that up is on Friday, 27th November 2020. Then the first How can I set up the first sending date? I don’t see the way to set up correct month and year…

Probablly there should be an easier way to do this?

The second workflow sets in the backend, which sends recurring emails.

You have it exactly right. To schedule doing the initial one email, I recommend doing the following:

Create a popup that will be hidden, but you will use it to do some calculations. Add five four groups to it:

Group 1 - set the type to date and the data source should be Current Date/Time + days 7

Group 2 - set the type to number and the data source should be the day of the week number from the input the user chooses * -1

Group 3* - set the type to date number and the data source should be Current Date/Time + days 7 + days Group 2 Number extract day

*edit made to remove issue from first calculation. Change type to date and remove the day extract.

Group 4 - set type to number and set the data source to Group 3’s Date extract day * -1

Group 5 4** - set the type to date and the data source should be Group 1’s Date + days Group 3’s number

**Group 4 actually becomes Group 5 and the data source should be Group 1’s Date +days New Group 4’s number.

So, the actual formula for solving this is:

(current date + 7) - weekday(current date + 7 - DOW)

weekday = extract the day from the date that is calculated
DOW = day of week of the date of the next weekday you are trying to calculate

This will give you the date of the next day of the week the user selected. So, in the scheduled date, put Group 4’s date change hours to User Selected Hour change minutes to User Selected minute. That will schedule the first email to be sent at time you wanted.

When the workflow to send the first email is run, Step 2 will schedule the workflow again, but for the following week. Let me know if any of this doesn’t make sense.

Edits made to correct some issues.

@jdiaz Interesting… I see what you’re trying to do!

But I don’t understand why would you minus 1 from the selected weekday number in group 2?
Also a potential flaw might be when the current weekday is earlier than selected one. Then the first scheduled day can be in the same week.

What about this?

If, current weekday number < selected weekday number
then, target date is current day + (selected weekday - current weekday)

If current weekday # > selected weekday #
then, target date is current day +7 + (Selected weekday - current weekday)

Do you think this would work?

Then the following question is How the capture current day’s weekday number.

@ohyoonkwn - you are not subtracting 1 from the group 2 number, you are multiplying it by -1 to turn the day of the week number to a negative number. That way, when you do the math in group 3, you are not adding days with the group 2 number, but actually subtracting the days.

I have test the method I laid out and it worked regardless of the day of the week the user chooses. Looking at the method you outlined, it makes sense, but you will need to test it. The other thing to take into consideration is that you have two different equations, so you will have to have an If/then statement of some kind to pull the right answer. Test it out and see how it goes. For capturing the current day’s week number, just do current date/time extract Day.

1 Like

Do you express the day of the week as 0 (monday) to 6 (sunday)?

Yes. That is how bubble does it with the day extract, so I would follow that method.

But when I use ‘extract day’ it return 2. and today’s Tuesday.

Sorry, I messed up. 0 is Sun on the extract method, 6 is for Sat.

Thank you @jdiaz I managed to set it up eventually!! You helped me a lot to figure out how to handle the date operation.

Somehow your logic doesn’t work for me. So I end up using if/then in a workflow. I think the logic does not accommodate the condition when the user’s day’s choice of the day is within the current week.

@ohyoonkwn - glad you got it working. I went back over it this morning and realized I had one issue in my method. I made edits for anyone else that might happen across this. Good luck with your app.

Now working on the email things…
Thanks for updating your method! I’m sure it helps others too.

Hey there! we just published a plugin & guide to make this easier!

If you give us an app name, we can have you try it out for free.

This topic was automatically closed after 70 days. New replies are no longer allowed.