ID from last inserted record does not refresh


I do a reccursive insert with a JS script and found a way to get the id of the inserted row.
But the var return always the first created id and does not refresh accross iterrations.

My code :

And the query :

What execution return :

But after execution we can see that the last version of the variable was 511 instead of 505 :

I had (have) a lot of trouble with recursive scripts in retool. I think it has to do with the script running faster than Retool updates the object you’re expecting an updated value from. The way I handled this was by adding delays when I know another trigger has to update a variable, usually 2000ms. I know there are better ways, such a promise functions/asynchronous functions but I’m entirely self taught and only recently starting using javascript specifically for this so I’m not familiar with those options.

Thank you I will try this, I'm also quite new in JS :slight_smile:

The delay helped for my inserts, but still no refresh of the id returned :frowning:

Found the solution with await :