Issue: When I try to get the new id value, it doesn’t give me the right value… I tried many things and asked ChatGPT but none of the solutions solve the issue…
Welcome to the community! Thanks for this detailed question.
I recommend copy & pasting this code into a Javascript query instead of a script. Then, in the Advanced tab of the query, check on “Keep variable references inside the query in sync with your app” (at the bottom of the Advanced tab).
For performance purposes, by default, the value of external (to the JS query/script) variables are only read when the JS query is initially called. In order to refresh the value within the JS query itself, you need to check the optional Advnaced setting on. We don't have this setting on scripts