Triggering and accessing query results within a single JS script

I am having trouble accessing updated query results from within a single JS script. It seems that the first time the query is triggered, the results are not accessible from within the same script that triggered the query. When I run the same script a second time, it gets the results from the previous run of the script.

This is what I am trying to achieve from within a single JS query script:

  1. Run a query using the .trigger() method.
  2. Assign the query results to a variable.
  3. Use the values in the variable for some conditional logic.

I have attached screen shots to illustrate the result I am getting in chronological order. The code in the screenshots also show some of the methods I attempted to access the query result variables.

I was able to solve the issue by assigning the triggering method to a variable and accessing the query results of the variable.