Change field value on specific date

I am trying to change the value of a field in the database on a specific date/time.

I have a date field in the database, data type is “game”, let’s call it’s value “1/27/2021 04:00pm”
I also have a number field in the database, data type is “user”, let’s call it’s value “6”

When the current date/time is equal to the game date field (ie 1/27/2021 04:00pm), I would like to reset the users that are within that game’s number field to “0”. I created a “do when condition is true” workflow (below), as well as the specific action which is to change the list of users but this does not seem to be working.

image
image

Any help would be amazing!
Matt

You’ll need to use a backend workflow for this.

Set up a backend workflow that changes the relevant numbers to 0.

Then schedule that to run on the ‘date/time’ of the game.

Thanks @adamhholmes - I have tried to set up a this backend workflow but am not seeing the right results… any resources that can take me through each of the steps??

Thanks!

@adamhholmes figured it! Thanks for the help!!

1 Like

@adamhholmes apologies to come back to this, but it appears I haven’t solved the problem as I thought I had. The workflow is running as planned, but it is only sending the email to and applying the changes to one user, rather than a whole list of users. To recap, what I would like to happen is when current date = a specific date, an email is sent to all users and the workouts this week field is cleared. I have attached my workflow below;

Backend Workflow:

  1. Set up endpoint

  2. Send email

  3. Make changes to user

Workflow:
4) Do when a condition is true - when current date = end date
image

  1. Schedule API

Apologies for long-winded message and hugely appreciate any help as I am completely stuck! Thanks in advance.

Your backend workflow is set up correctly so there’s no issue there.

But it looks like you have some errors in the way you’re triggering the workflow to run.

Without knowing more about your app’s datastructure, and exactly what you’re trying to do I can’t say exactly what will work for you, but here are a few things I notice…

Firstly, you’re using a ‘do when condition is true’ workflow in the browser to trigger the backend workflow. That will only work when the user’s browser is open. So unless your users keep their browser open and logged in to that specific page 24/7 it’s not going to work reliably to trigger a backend workflow such as yours.

Also, the standard Bubble current/date time doesn’t update in real time, so you can’t use a ‘do when condition is true’ to trigger something based on a time changing or updating.

Besides, if you’re scheduling a backend workflow to run at a specific time, it doesn’t make much sense to trigger that workflow at that exact same time (if you want to do that you can just schedule it for ‘current date/time’ instead so that it will run immediately, or even not bother with a backend workflow at all - just run a browser workflow to run the actions).

In terms of who the workflow is running on, again I don’t know how your database is set up or who exactly you want the workflow to run on, but you’re currently running the workflow on the current page group’s members.

So if it doesn’t appear to be running on all of the users you want it to be then it’s probably either down to how you’re selecting and filtering that list, or it’s to do with the various conditionals you’ve got on the workflows and actions. So either check how you’re selecting the list to run it on, check your database User entries, or rethink what conditionals you need/don’t need and how you’re setting and resting those fields.

Again, without knowing your app I can’t be specific, but from what I’ve seen it looks as though the best way to achieve what (I think) you’re trying to achieve would be to schedule the backend workflow to run on the date of the game whenever that game is created.

So wherever/however you add ‘games’ to your database, in that same workflow schedule the backend workflow to run on the date of that game, on whatever list of users it is that the workflow needs to be run on.

Be aware though, that when you schedule a workflow to run on a list on a future date, you’re scheduling it to run on that list as it exists at the moment you schedule it, NOT what it may look like at the time it’s scheduled for.

In other words, if you schedule a workflow to run in a week’s time on a list which contains 100 users at the time you schedule it, then another 50 users are added to that list before the scheduled date arrives, the workflow will only run on the original list (of 100 users) it was scheduled for.

So you’ll need to add an extra backend workflow to schedule the other one for the ‘correct (current) list’ if you want it to run on the list as it exists at the time it runs.

Huge help @adamhholmes, thank you so much for the detail Definitely being messed up by the “do when condition is true”. I completely get the workflow list will run on a specific list at that time which for this app is no problem. Is this true also for the date? For instance when the game is created the first run date is 5th Feb will it only run on that date, even if I manually change the date after creating? I am asking as I am trying to test without having to wait a week!!!

If you schedule a workflow to run at a specific date/time then the only way to stop that from running on that date/time is by cancelling it.

So, for example, if you’re using a dynamic date (from a database entry) to set the scheduled date of a workflow and then, after you’ve scheduled that workflow, you make a change to the database entry’s date, that won’t have any effect on the workflow you’ve already scheduled - that workflow will still run at the date/time it was originally scheduled to run.

So if you need to change the date a workflow is scheduled for, you first need to cancel the existing workflow, then schedule another one for the new date. To cancel a workflow you’ll need to store the workflow ID somewhere in your database so that you can reference that when using a ‘cancel scheduled workflow’ action. So, for example, you might add a field on your ‘game’ datatype to store the workflow id for the game’s current workflow. When you schedule the original workflow just get the ID for the workflow and store it on the field.

If/when you change/update the game/date, you can delete the currently scheduled workflow, and schedule a new one for the new date.

Got it - thanks so much again for all your help!

1 Like

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