Backend trigger based on data?

Hello, I am working on an app for the classroom. A teacher creates a positive notice (to the database) when a student does the right thing. I would like to trigger an email to the teacher every time a student has received 3 positive notices. I cannot figure out how to trigger the email based on every 3 notices created in the database. Any ideas?

First, make sure that your app plan supports database event triggers because sadly not all plans have the full functionality of Bubble.

Next you want to setup the trigger as follows:

This is the condition you want (or something similar):

Screenshot 2022-11-08 1.46.27 PM

Be sure in that “Only when” search you are grouping on each student otherwise it would send out an event everytime there are 3 positives indifferent of which student(s) received the positives.

Hi there, @benrcalvert… are students tracked in your system as users or in their own data type? If so, I would consider having a field (number) associated with a student, and I would simply increment the field by 1 every time the student receives a positive notice. Then, when the number reaches 3, I would send the email and set the field back to 0.

Anyway, just some food for thought there, and I hope it helps.

Best…
Mike

2 Likes

Or what that guy said :point_up: Always more than one way to do things, whichever works best. You could do it per @mikeloc 's suggestion and without a database event trigger.

1 Like

Mike, that you so much for your kindness! Thank you for taking time out of your day to randomly help someone. Very cool of you.

1 Like

Thank you so much for you help. Much appreciated.

So I am trying your solution but cannot piece together the missing steps. When I create the “new database trigger” my "only when options are dramatically different than the ones you show. Maybe I missed a step?

So in this case because of the limited “Only when” options, you have to just leave that event “Only when” blank. What that means is that every time the type “Positive-Notification” is updated the event is going to fire. You might need to restrict this for performance reasons later but for now we can just get it working so you can move on to your next task.

On your action (which you will create inside of that event) is where you’ll put your “Only when” clause so that it only fires the action when the condition is met. So while the event will fire everytime a data type record is updated the action will only run when the condition you place on it is evaluated as true.

Thanks for your patience… I am teacher and clearly not great at this yet… So within my email action I am searching within my positive notifications, grouping by student name, then selecting the “modulo” as you indicated but when I enter the "3 is " it deletes that part and show as invalid… Where did I mess up?

Try typing “3” and not “3 is”. The “is” is an operator that will pop up after you enter the 3.

I truly appreciate your help. You are so kind to help random people. I was able to enter the full expression with your guidance making “is” the operator. It turned blue. I sent 6 positive notifications to the same student but no email triggered. Sorry to be such a pain, but any last ideas?

For debugging I wouldn’t fire the SendEmail action. I would use “Set State” to set a variable on the page or add a value in the database (Create a thing) so you can confirm if/when your logic is triggering. Once your logic is good, then you can convert it to the SendEmail action. There are a lot of reasons why an email could fail to send.

You should make sure that the logic is firing correctly first. When I tested the logic in a test app, I used Create a Thing to confirm the logic I was giving you would in fact work correctly. I would take this step next and see if there is an issue with you logic or with the SendEmail action.

Thanks again for you time and generosity… I am in way over my head. Still not working to “create a thing”… Final question, do you do side work helping people like myself put finishing touches on apps? I’ve got 90% of the work done but there is this, and a couple other things, that I continue to go in circles for hours on and am making no progress. If you do not do that sort of thing do you know anyone that does?

I do that sort of thing. :slight_smile:

But seriously, I’d be happy to help you out, so hit me up via direct message if you are interested.

1 Like