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
?