Using variables outside wixData.query code?

Hi Community,

I am not experienced in coding and would appreciate some guidance with the following:

I have to run two different wixData queries and i would like to store the results in a variable. The problem is that I cannot use this variable outside the wixData.query. Question: What is the best way to store the outcome of query1 and use the outcome in query2?

Here’s my code as an example (Dest1 is filled in the first query). I would really like to know how to fill variables and use their value outside the query code.

Try changing the scope of Dest1, by putting it outside the query, in other words, declaring the l et Dest1 = … underneath let DestWallet

Thanks, but this unfortunately doesn’t work either. The value of the variable doesn’t get updated. I read on other community posts that this is due to asynchronous processing and any code should be put right after .then((results)

However, I don’t see how this can work if the code after .then((results) requires a result from a previous query.

@gregor No, you are confusing things. This is a scope problem. Have you declared dest1 as

let Dest1;

right below l et DestWallet ?

And then of course change

let Dest1=results.items… into

Dest1=results.items …

Hi Giri,
Yes, I have edited the code but it still doesn’t update the value of Dest1. Here is the revised code.

got the same problem with scoping… i don’t get why i won’t pass the value from interior…