Success handler triggering to soon

I am building a simple app that has a table connected to a firestore collection.
New rows need to have a special ID, that is the max of the current ID + 1.

I thought this would be simple, but I am having a challenge here.
This is my create new row query (createGuessWhatQuestion):

The document ID is based on another query that retrieves the maximum ID +1 (getGuessWhatQuestionNewId).

After adding a new row I triggger the JS query to create the next ID on the success handler.

This is the code for creating a new ID:

Now the problem is that this doesn't always work. Although I am updating the query from firestore before generating the new ID (await getGuessWhatQuestions.trigger();), sometimes the new added row is still not there.

What I think it's happening is that my createGuessWhatQuestion triggers the success handler, before making sure the new row was properly added to the firestore database.
Is this possible? Should I be doing this another way?

Thank you.

Hey @pedrocarloto!

Do you have the following advanced setting checked in your app?

Without it, will still refer to the data from the previous call even if you use await, which may be causing this issue. Alternatively, you can try assigning its data to a variable, something like:

const questionData = getGuessWhatQuestions.trigger();
/* your code */
for(let row = 0; row < questionData.length; row++){
  /* more code */

Let me know if either of those work!

Hey @Kabirdas!

Just enabling the "Keep variable references (...)" did the trick.
Maybe this should be enabled by default? :slightly_smiling_face:

Thanks a lot for the help.