utils.exportData() throws "data must be a plain object or array"

  • Goal: An eventhandler on a table-row button should trigger a file download

  • Steps: The function used to work until it suddently stopped working. I'm not aware to have changed something related to that function.

  • Details:
    When the app is freshly loaded the download function fails with the error message data must be a plain object or array in utils.exportData().

When i switch to Edit Mode the function still fails when clicking on the button, but when I click on the Run button of the query the query returns a result.

And the bizarr thing is that from then on the download button in the grid works also and the download starts and completes successfully. :person_shrugging:

Any hint is welcome!

1 Like

Hi @merrycoder,

Welcome to Retool! Can you share a screenshot of your actual event handler for that download button? I would have expected to see a call to apiQueryDownload in your first screenshot, so I'm curious as to how that download is set up.

Hi @MikeCB

thanks for answering - here's the screenshot:

Ok, I think I know what's going on here.

It works in Edit mode because you've manually run apiQueryDownload so there is a value in .data. Because the download action needs to run a query and then download the result, you need to set this up a little differently. Right now you're trying to export the data in that query, but that query never gets triggered. This is what I'd suggest:

  • Change your event handler to control a query
    • Pick your query
    • Choose "trigger" as the method
  • Under your query, add an onSuccess Event Handler that does the utils.exportData action.

Alternatively, if you prefer a more script based approach, you can change your download event handler to run code, and do something like this this:

await apiQueryDownload.trigger()
utils.exportData(apiQueryDownload.trigger, 'swissrets', 'json')

Which will run the query and then call the export.

Thank you @MikeCB - you saved my day. it works now :grinning:

1 Like