Check for condition

I want to implement the following logic. How can i do in Bubble?

When member clicks the check in button and the member has not been checked during today, then check the member in. Else show a message that the member has already checked in for the day.

I have one data type called member which has a field called check in. This is of the type date that stores the current date/time of the check in.

Here’s how. You’re going to wait to either:

  • Have a database table add a new row each time a user checks in (e.g., fields = user, check-in date/time)
  • Or, update a field on the user table that has “last time checked-in”

It’s easier to put it on the User Table, but then you lose historic data about all of the times the user checked in since the last time checked-in gets overwritten each time the user checks in.

Once you have that in place, then either:

  • Run a workflow that has 2 actions. Action 1 checks the user in, and it is set to only run when the last time the user checked in was yesterday (by doing a lookup on that database). Then, add a 2nd action that shows a message that the user has already checked-in and have it set to only run when the user has already checked-in that day.
  • Or, have 2 different workflows. The 1st workflow is triggered when user clicks the “check-in” button and when the last time they logged in was not today. And, have a 2nd workflow that runs when user clicks “check-in” and has checked in already today.

That’s it. Pretty straightforward.

Note - you may want to think through how you handle local time zones instead of forcing everyone to a standard 24 hour period that might not be midnight to midnight in their local time. Of course, this really depends on your desired customer experience. And, you can always add this later without change the core infrastructure of this, so no need to address for now if you’re just getting something up and running.

All the best,
Scott

Makes sense Scott. I have been trying to check for the condition where the last check-in is not today. How can I check for this specific condition in the tool.

Good question. Let me ask, what’s your definition of “today” ?

Is that the last 24 hours. Is that anytime since midnight in my local time? Or, perhaps something slightly different?

Also, do you need to guarantee that user’s can’t trick your system (e.g., by changing the clock on their computer)? If so, it’s quite a bit harder. Typically, it’s rare for users to realize they can trick an app by changing their own clock so I’d ignore that for now, unless you’re exchanging money or something else very material.

today is since 2 am. This is an inhouse app that will be only used by me to check in members. so not worried about changing clocks.

Easy way if it’s just you - show the time of last check-in on the page, then, and for you to look at it and determine whether that’s within the last day.

More technical solution would be to do a search for and filter based on the time to see if the count of entries is equal to 1 for check-ins within the last day. To actually do the math, you’d probably want to do something like do a search for the date and time of last check-ins’ minus current date and time, if less than current date and time minute today at 2am, then they already checked in today.

Note - you may want to add values to custom states to make the math easier. Bubble doesn’t yet support parenthesis in calculations, so using custom states enables you to do math to calculate something and then store it as a custom state, which can be referenced in a different math statement.

Best of luck!
Scott