giving undefined value

I have a variable created with id ‘test1a’ with value of ‘xyz’. In a javascript function, I am trying to set the value of this variable using‘test1a’, test1b) to use in the text on my page and in a progress bar through app connect. However the text originally shows ‘xyz’ as expected after running the function the text disappears, and the logs show undefined. Does anyone know the mistake I am making? Thanks

Variable definition:
<dmx-value id="test1a" dmx-bind:value="'xyz'"></dmx-value>

Javascript code:
var test1b = ‘abc’;
console.log(test1b);‘test1a’, test1b)
var testres1 = dmx.parse(‘test1a.value’);


A lot of the time with dmx.parse you need to make sure the document is fully loaded before you run the JavaScript function/code.

If that is it, you’ll need to either call the function at a certain time or load event, or in your JavaScript code use the relevant document onload event.

I don’t have the exact code in front of me, but pretty sure your JS code is running before the dmx value has actually been defined.

Thanks Phillip, just to clarify, if it’s not clear, I’m not trying to parse the value, that seems to work.
I am trying to set the variable value using Basically I have a button (it’s part of a map api which can only run a JS function) which on click I want to set the wappler variable as something. However while the value starts defined, once I run the function to change the value, the variable becomes undefined.

Ok no worries. It just looked like your last console log that was showing as undefined matched up with this log/var value.

What you might find better, as i have recently discovered, is that you if you want to change the value of an app connect variable (like in your example) you can use dmx.parse. Like this:

dmx.parse('var_1.setValue("xyz")') (or you can have the value being any variable etc from your JS code)

With, it does create a variable with that value, but its not selectable in the UI in app connect. But if you use dmx.parse and use the .setValue("value")' you can actually change the value of an app connect variable.

I’d try that.

That worked, thanks so much!

For anyone else wondering:

It didn’t work when I tried:
var testvar1 = ‘abc’;

However it worked when changed to this:
var testvar1 = ‘abc’;
dmx.parse(“var.setValue(” + testvar1 + “)”);

Hi Philip,
I’m struggling to get data out of JS and was interested in the topic above and use of dmx.parse to update “wappler” variables. i can update the “wappler” variables with static data e.g

js code
chart: {
height: 400,
events: {
dataPointSelection: function(event, chartContext, config) {
dmx.parse(‘selection.setValue(“22”)’); /* in this case the variable selection is updated to be 22.

if i change to try parsing the variable a
(that contains the index of the series i clicked on happened to be 7) the console.log shows this setup properly but the “wappler” variable selection is updated to null not the 7 expected/hoped!!

I’d appreciate any thoughts on how i can get dynamic data out of JS back into wappler to use? I’ve also tried…


Hey @NGM

Firstly, there some info here in formatting code for posts which helps neaten things up for us to read on the forum :slightly_smiling_face:

Secondly, I’m not sure on the exact syntax to use dmx.parse to set the value of a Wappler variable, that’s when I use all the time.

Based on your code above I’d try:'selection', a)

Now remember, this won’t update the variable you’ve created in the UI. It will create a variable that you can use in you app in code though. So you can use it the front end by using {{selection}} anywhere you’d want to use it. Such as dmx-bind:text="{{selection}}"

To be honest, I’d forgotten about using .setValue. not sure if it works all the time and you can just fix the syntax, but' or ' will definitely work for you.

Thanks Philip