Looking for suggestions on how to control the order of function execution?
In my work with Oracle APEX, I've set up a button labeled "export" that captures the ROWID of selected rows in an interactive grid and passes these values to a page item. The goal is to trigger a process that requires a submit. I've also created a JavaScript function called downloadFile()
which generates a file download. Now, my challenge is to ensure that the downloadFile()
function only runs after the submit. However, I want to keep just one button to handle passing values to page items, submitting the page, and then running the downloadFile()
function.
I've attempted declaring the function globally within the page, in the JavaScript section (Function and Global Variable Declaration), and calling the function after the submit in the button. Yet, this resulted in a blank file because everything executed simultaneously, and the values were set in the page item after file generation. I also tried adding the submit action to the click event of the APEX$ROW_SELECTOR
column, but it only worked for one row at a time since the selection was cleared after each submit.
I did find a workaround using two buttons. Clicking the first button captured the ROWID of selected rows, applied the submit, and clicking the second button triggered the downloadFile()
function to generate the file. However, I prefer not to have two buttons for this process.
How can I ensure that the downloadFile()
function runs only after the submit while keeping just one button to handle all these actions?