Variable not being reset to empty state

I have a variable, dealsWithIssue, that I'd like to set to an empty dictionary with each invocation of a Run JS Code resource. My JS code looks like the following

function saveDealIssue(dealId, issue) {
  // load all issues
  const dwi = dealsWithIssues.value
  const issuesForDeal = dwi[dealId]
  if (!deal) {
    dealsWithIssues.setValue({...dwi, [dealId]: [issue]})
  } else {
    dealsWithIssues.setValue({...dwi, [dealId]: [...issuesForDeal, issue]})
  }
}

function doStuff() {
   // ...
   saveDealIssue(123, 'lol')
   // ....
}


dealsWithIssues.setValue({})
doStuff()

I find that if I run this multiple times, the state for dealsWithIssues goes from
{123: [lol]} to {123: [lol, lol]}, etc... (where new entries keep being added with each subsequent invocation)

How can I correctly reset the state of my variable prior to calling doStuff?

1 Like

Hey @paymahn! Welcome to the community. :slightly_smiling_face:

It's not obvious, but you should be able to fix this issue by toggling on the Advanced option to Keep variable references inside the query in sync with your app.

Without that particular setting, Retool won't dynamically update the value of variables during execution of the query in order to increase performance. I hope that helps!