Question about "For Each loops" type operations

Hello,

I am putting together a gig tracking app. What I would like to do is have a user notified when new tours are added by the bands that they follow/track. When the user initially follows a band, the current number of tours is stored in a data field.

For a very basic version of what I want to do, I figured upon page load I could update a separate field with the bands current number of tours, and if that value has changed (i.e new tours added) I could compare the initially stored number of tours with the current number of tours, and if they are not the same, display an alert/notification.

I can get this to work in a scenario where a user is only following one band. But of course, real world application would have them following many, so I would need the current tours count to be updated for all the bands that a user follows. So I need some way to go through each band that the user follows, log their current tour numbers, update the relevant field with that number, and then run an alert if the numbers don’t match. My novice level of competency in Javascript would have me doing a “For Each” type function to solve this but I can’t seem to figure out how to replicate that in bubble?

Thanks.

Hi there, @phillipwalsh984… I’m pretty sure you could use a backend workflow to do what you have described, however, as I was reading your post, a thought (and maybe not a good one) came to mind.

Instead of messing with counts, could you just fire off a workflow (and almost certainly a backend workflow) when a band adds a tour that finds all of the users who are following that band and “sets” an alert for them (whatever setting an alert means, and I can think of a number of ways to accomplish something like that)? Unless I am missing something obvious (and that could easily be the case), what I am suggesting accomplishes the same goal of alerting users when a band they are following adds a tour, but it does so without having to track, update, and compare any counts.

Anyway, just food for thought, and I hope it helps. If I missed something obvious and this response is garbage, well, just pretend I was never here. :wink:

Best…
Mike

3 Likes

Good point from Mikeloc, this should work. You can also take a separate table in which you store a list of band ID’s that have new events added. This way you can even be very precise and say “band 1, band 4 and band 7 have new events!”.

1 Like

Thanks for all the suggestions.

After racking my brain for a good while I managed to come up with a simpler solution - not that the ones offered didn’t have merit, but for what seemed like such a simple operation, having to set up backend APIs or even using plugins seemed like using a sledgehammer when a toffee hammer would do the trick, so to speak. Plus I don’t think I’m ready to dive down the rabbit hole of backend APIs just yet (probably the main reason tbh).

What I ended up doing was creating a data type “NewTours” with fields of “BandName” and “Followers”, and every time a new tour is created, the bandname is populated with the relevant bandname, and to the followers adds a list of users who follow that band.

Then on the user end there’s a group focus containing a RG which only displays when the NewTours followers contains the current user, the bandname is in the current users bandsfollowed, and the count is >0 (i.e, there’s a new tour). Inside the RG there’s a button to acknowledge which then removes the current user from the NewTour Followers field (so they won’t get alerted again for that tour).

Obvious problem down the line with this method is that if a band is doing a 40 show run then the user is going to get 40 separate notifications but the idea is that the user will modify settings to narrow down alerts for say tours within certain countries/cities etc, as if you live in UK you won’t really be interested in hearing about tours in the US.

Anyway, I’m rambling. Thanks for the suggestions, definitely gives me something to come back to later on for a more elegant solution.

1 Like

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