Retool Storage File Load Problem

I have a module with a retool storage query set up which gets a png file from Retool Storage. The problem I am having is that I can't seem to force it to load prior to when I go to use it in a JavaScript function called by a button component. I've tried triggering the query like this in the JavaScript:

async function createPdf() {
const image4 = await pdfDoc.embedPng(;

The MSSLogoQry takes too long and is still null when the next line is called. I've tried adding a wait period in between the two lines. That works if you run the code twice, failing on the first time it is run. I don't want to have our users click the button to run this twice!

I've also tried to have the Retool Storage query run upon loading by setting the Run Behavior to "Automatic". This seems to work when it is in a stand-alone app, but fails when it is used in a module, almost as if it never gets the event for the page load.

I've also tried various ways to trigger the query from various event handlers of components etc but nothing seems to work.

Any ideas? Thanks in advance!

It turns out the problem wasn't with the Retool Storage per se but rather with using Preloaded JavaScript. a few lines of code further down I called a function from the Preloaded JavaScript. By moving the function directly into my script it then worked as it should. Now I need to figure out why it doesn't like the Preloaded JavaScript!

Did we assign the function to the window like window.createPDf = createPdf?

I don't understand "assign them to the window scope". How does one do this?

Here is an example: