Issue with file download and dynamically created file

Here is the problem.

Background
My data query is based on poll data and returns totals
I have a repeat based on data returned
Each record has a type_id
in the event of type_id == 7, this indicated that the response is a text response rather than an pre selected option therefore cant be summed obviously
So as an alternative i want a button which, when clicked, runs a server action which concatenates all the text responses and downloads the file of responses. (for later use with AI)

To here I have no problems,

so i have a serverconnect->load attached to the click event which creates the file to download and also download action set

The issue is timing, the download fires before the server action completes and i cant find a way to either defer it or fire it from a dynamic action
Anyone any ideas?

It's not a good idea to have both link/download and server action on click, as you then hit these race conditions.
I can think of two solutions to this problem:

  1. Use the server-side download component in the server action.
  2. Use the app connect download component and call it on server action success on the page.

The only way I could find to address this was to separate the two actions so you have a button to create the file and then another to download it. You could put a condition on the download button to only show when the file exists to make it a bit of a better experience for the user.

That's the solution oi was looking for , completely forgot about the download component, that allows me to call it from a success action. Works perfectly.
Thank you!

1 Like