Can't get dmx.parse to work inside script

Hey guys, I’m trying to learn how to use variables and arrays I’ve created in Wappler with third party libraries. I can’t seem to get dmx.parse to work inside a script. At this point, I’m not sure if I’m doing something wrong or it’s a bug. To break it down to the simplest solution, I’ve written the code in the screenshot below. This is the only code on the page.

When I open the page and look in the console, the console displays a “TypeError: Cannot read property ‘get’ of undefined” error and the value of the variable displays undefined (screenshot below). If I run, dmx.parse(‘content.var1.value’) in the console, the value of the variable displays correctly.

I’m spinning my wheels and getting nowhere at this point. Can anybody point me in the right direction?

Have you tried to add the script at the bottom of your page?

The script is at the bottom of the page. The code in the first screenshot is the only code on the page.

This is a matter of timing. The script is running before the var is created.

Try putting your script inside of this:


$( document ).ready(function() {
    // your code here
});

Another method of dealing with this is to create a js function and then call that function from a flow that is set to auto run.

And if you want to reference data returned from a server connect, you can call the function on success of the sc.

2 Likes

The ready function worked like a charm. Thanks Ken!