I tried to assign a js variable to a AC variable …works with hard value, bu not with js variable
browservalue = dmx.parse('lang.value'); // store 'fr'
alert(browservalue); //display 'fr'
dmx.parse("sendlangtosession.setValue('hard value ok');");
dmx.parse("sendlangtosession.setValue(browservalue);"); //not ok
Error is :
SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse (<anonymous>)
at sessionManager.js:28
at Array.reduce (<anonymous>)
at n.getData (sessionManager.js:26)
at n.set (sessionManager.js:12)
at Object.data.<computed> (BaseComponent.js:475)
at parser.js:714
at t (parser.js:464)
at parser.js:455
at Object.dmx.parse (parser.js:388)
Is it possible be that when that first variable browservalue is set, that the app connect variable Lang hasn’t filled loaded in the DOM?
I know from my experiences using JS in Wappler I always need to either call a JS function on an event in Wappler (I.e. button click or onload for a server action) or use other trigger events like document ready/onload etc.
The browservalue variable is a JS variable. When you pass it to dmx.parse inside double quotes, it assumes that its a DMX object, which does not exists. Hence the value that gets set in the session is undefined. Which leads to the error your are seeing… unexpected token u.
Correct code would be: dmx.parse("sendlangtosession.setValue('" + browservalue + "')");