I have a sign up mechanism for sellers which asks them to choose a day from a dropdown and define an open and close time.
That gets saved to the database in a table with columns for:
- Day - value of day from dropdown (Monday - Sunday)
- Open - value of time from dropdown (00:00 - 23:30
- Close - value of time from dropdown (00:00 - 23:30
- Plus the usual modifed date and created by fields
This works… BUT… The problem I have is that if the user forgets to change the day drop down, or selects the same one twice, I get 2 rows for one day.
So, I only want to create a new row if there isn’t already a row for Monday for that user.
I’m relatively new to this so I haven’t got a clue where to start looking!
Hi there, @andy11… like pretty much all things Bubble, there are a number of ways to do what you described. One of those ways would be to put a condition on the workflow event to create a thing in the data type only when a count of a search for a thing created by the current user for the selected day is 0. As you can imagine, though, such a search might not be the most performant way to go if you have lots of sellers creating lots of things in the data type.
Another way to go (which might be viewed as a bit “unconventional”) would be to remove the possibility of the user creating a duplicate thing for the same day by removing days from the dropdown as a user creates things for them. You could make that happen by having a list field on the
User data type that stores a list of the days that have already been selected. With that field in place, you would configure the choices source for the dropdown as all of the days minus the list of days stored for the current user, and then you wouldn’t have to worry about checking for duplicate things.
Anyway, those are a couple of ways you could go, and I hope this helps.
Thanks. After some trial and error, I’ve solved half the problem with this:
So, OpeningTimess:each item’s Day is the entry in the DB. DayofWeek’s value is the dropdown on the page.
The problem is that it now won’t allow any other user to add times for days that already exist.
I’ve add the email address when a row gets added so I’m saying:
Only when a day doesn’t already exist AND the UserID contains the current user’s email address
Same is the first image but UserID is the current user’s email address which is written when a row is created.
That still stops new rows being added.
In the first screenshot, do you have any constraints on the
Search for OpeningTimess? If you don’t, try adding a constraint on that search where
Created by = Current User and see if that does the trick.
You genius! That’s done the trick. Thank you!