Dmx.parse() is only working when it is inside a JS function

Wappler Version : 3.4.2
Operating System : Win10, NodeJS / Docker project

Expected behavior

Firstly, i’m not sure if this is SUPPOSED to work this way, but i would have thought it should.

When you use dmx.parse() NOT IN a function it would work normally, such as setting a var value.

var test = dmx.parse('local.data.showTeams'); 

Actual behavior

When you use this in a custom JS file (loaded through script tags) you get this error:

parser.js:390 TypeError: Cannot read property 'get' of undefined
    at t (parser.js:655)
    at parser.js:741
    at parser.js:741
    at parser.js:455
    at Object.dmx.parse (parser.js:388)
    at schedule.js:2 // this is the custom JS file loaded in script tags

If it is used inside of a function and the function is called, then it works fine i.e.

function showTeams() {
    calendar.setOption('resourceGroupField', dmx.parse('local.data.showTeams'))
}

Also, the dmx.global.set() works FINE outside of a function like this example:

dmx.global.set('test', true);

How to reproduce

  • Create a NodeJS / Docker project
  • create a custom JS file and load into page with script tags etc
  • use the dmx.parse() function outside of a function and see if it works or throws an error like the above example.

Often this is a matter of timing… the non function usage is happening before the dmx stuff is all loaded. The function works because you are calling that after everything is ready. Try wrapping the problem inside of a ready function. Our place in a regular function and call that function using a static event when the page is ready.

I’ll look into that. The script was deferred and loaded after the dmx-state manager…but perhaps it’s still a timing issue.

This was the problem… i should have realised this ad I’ve dealt with this before. The only issues is that (based on my limited JS experience) once you wrap something (or even all of your JS) in a function like

$(document).ready(function(){
//functions to be executed
});

It becomes a lot harder to access the functions inside the main function… anyway, its not a Wappler bug so its solved…just need to find a good solution to work with :slight_smile:

It’s been mentioned on here before but you can also trigger your function from a Flow, and then you’re also able to add a wait step just before the trigger. That way you shouldn’t have you use the ready function.