List of info from RealTime DB only populating on second click

Hello, I’m having a weird issue when I try to create a list of data retrieved from Realtime DB. My app has a database of user IDs and each user is also assigned a play ID from OpenSignal so that I can send push notifications. What my code does is go through each user that I want to send a notification to and gets their play ID. However, when I click the button that triggers this function and displays the list, the list isn’t displayed. But when I click the button again, the list is displayed! I really don’t understand why this is happening. Any help would be appreciated.

This is the structure of my database (there are two types of users - customers and businesses):

and this is my block:

When I click the button to display the usersToNotify list, it is blank. But then when I click the button again it displays. Any help would be appreciated!

You are not alone!

The firebase GET and SAVE blocks are asynchronous (as evidenced by the THEN DO section). When you put them in a loop or execute one after the other, erratic behavior is the norm. I have found 2 solutions to the problem.

1 Like

Thank you!!! I was trying to figure out this issue for so long and this worked. You’re a life saver!