Can't test workflow through workflow editor (need to launch through preview mode in editor)

So I have a file uploader to which a workflow is handling the upload through a form-data POST to Xano in a Javascript code block.

I have some issues testing this workflow: when I trigger the workflow through the preview mode of the editor, it works as expected. However, when I trigger the workflow in the workflow editor, it fails at the Javascript block.

Here’s the error:

name: "TypeError"
stack: "TypeError: Cannot read properties of null (reading 'files') at eval (eval at executeCode (https://editor-cdn.weweb.io/public/js/index.b8c3786f.js:977:6231), :9:40) at eval (eval at executeCode (https://editor-cdn.weweb.io/public/js/index.b8c3786f.js:977:6231), :59:3) at executeCode (https://editor-cdn.weweb.io/public/js/index.b8c3786f.js:977:6231) at _t (https://editor-cdn.weweb.io/public/js/index.b8c3786f.js:2455:23773) at It (https://editor-cdn.weweb.io/public/js/index.b8c3786f.js:2455:22461) at It (https://editor-cdn.weweb.io/public/js/index.b8c3786f.js:2455:22713) at async It (https://editor-cdn.weweb.io/public/js/index.b8c3786f.js:2455:22707) at async It (https://editor-cdn.weweb.io/public/js/index.b8c3786f.js:2455:22707) at async It (https://editor-cdn.weweb.io/public/js/index.b8c3786f.js:2455:22707) at async It (https://editor-cdn.weweb.io/public/js/index.b8c3786f.js:2455:22707) at async It (https://editor-cdn.weweb.io/public/js/index.b8c3786f.js:2455:22707) at async Ct (https://editor-cdn.weweb.io/public/js/index.b8c3786f.js:2455:21727)"
message: "Cannot read properties of null (reading 'files')"

Basically, it looks like the Javascript code block doesn’t have access to the uploader files when in the workflow editor context.

Here’s how those files are selected in code:

var imagefile = document.querySelector('[name="uploader"]');

Is there a better way to select files so that it works in the workflow editor? Or is this a limitation that we can’t work around.

Thanks,

Hi,
you should replace document by wwLib.getFrontDocument()

The editor is running the website inside the iframe, and depding on where you execute your code, the document variable may refer to something different.
wwLib.getFrontDocument() always return the correct document

2 Likes

Awesome thanks so much for the quick and detailed reply Aurelie!