#aync JS object function data not refreshed in widget when action calls that function

1 messages · Page 1 of 1 (latest)

lean vapor
#

I'm following the documentation in this link
https://docs.appsmith.com/core-concepts/writing-code/javascript-editor-beta/asynchronous-javascript-function-settings

There is an async function in a JS object which fetches some data from api's, and performs some transformations on it. This follows the dataloader: async () ={...} signature stated in the docs

A list widget shows the returned data. This data is binded into it using the {{JSObject.dataloader.data}}

An there is a date picker which is used to select the date range be used for the mentioned apis. This has for onDateSelected {{JSObject.dataloader()}}

The thing is, the widget does load the data adequately but only on page load. When the date is changed in the date picker, the function is apparently executed (there is a showAlert action executed at the beginning of it). But the data in the list widget is not updated. I've tested with fixed parameters for the function and manually executed it in the IDE. In that case, data is updated in the widget. Help!

The asynchronous function allows you to choose when you want to execute code. For example, you may want to delay the query execution or fetch the data on demand.

ashen dew
#

Hi @lean vapor , what else does the dataloader() function do?

You could also try adding a refreshWidget(List1) step at the end of the function. If that doesn't work, try changing the List widget data binding to JSObject1.dataloader().

lean vapor
#

this is the full function definition

#

I simplified names

#

it is actually called, loadTransactions

#

it just formats inputs adequately for an api fetch which then performs business logic

#

finally, a presenter function formats the data so its easily used by the list widget

#

I've tried adding refreshWidget but apparently it is not defined

#

And if the function is bound as suggested, the Async function error arises