[Bug]: Query.data Returns Undefined After Awaiting Query Run in an JS Function That Runs on Page Load #33335
Labels
Bug
Something isn't working
FE Coders Pod
Issues related to users writing javascript in appsmith
JS Evaluation
Issues related to JS evaluation on the platform
Medium
Issues that frustrate users due to poor UX
Needs Triaging
Needs attention from maintainers to triage
Production
Is there an existing issue for this?
Description
The user runs a query, then stores the data returned to Appsmith store. The code snippet used is similar to the below one:
However, the code does not run as expected and the value stored to Appsmith store is
undefined
, although theawait
keyword was used; hence, the query should have run before the result was stored to Appsmith store.This behavior is only present if the code is run on page load. If it is run manually, it always returns the expected result.
The workaround is to assign the query run to a variable and store this variable to Appsmith store by using the following snippet instead, which is safer:
However, the first approach should have worked too, since the
await
keyword was used correctly.Steps To Reproduce
Ticket with screenshots of the original code
Public Sample App
No response
Environment
Production
Severity
Medium (Frustrating UX)
Issue video log
No response
Version
Self Hosted
The text was updated successfully, but these errors were encountered: