I have a javascript query that is using setIn() to update a temporary variable from a form submit. The query get called correctly and I pass in the new value correctly via a trigger. However, the temp variable is not getting update unless I run the query twice. On only the second try does the variable get updated.
Triggering script from button:
const value = form1.data.switch1;
await updateYardPurchaseSetting.trigger({
additionalScope: {
category: 'purchaseSettings',
obj_name: 'testObject',
value
}
});
Idk if I am missing something. I had read that post prior to submitting my own post but at least I got confirmation about it being a good resource; so "thank you" for that.
I am trying to update field, not delete it. In other contexts using setIn is great and I get how to use it.
Do I need to "reload" the temp variable in some way? I tried that previously but something like:
@David_Adams this is a somewhat common "gotcha" with the way that queries are executed in Retool by default. For performance reasons, the default way that queries are executed makes a copy of the application state at the time the query is triggered, but that copy is static and does not update as you make changes within your query.
So when you call setIn and then subsequently look at .value - .value is still the copy that was made when the query started executing.
The reason it appears to work on the second run is that the first execution did actually work and the initial copy for the second run has the updated value that was set by the first run.
If you need to be able to access the updated values, you can enable the setting "Keep variable references inside the query in sync with your app" in the advanced tab - which will make things behave in the way I believe you're expecting.