Cannot parse variable

Hi All!

I get a strange error in the java console when deploying my application (as opposed to running it in Developer) that I cannot trace :shock:
Perhaps someone could give me a clue of where I should look? Thanks!
So, I am cloning a design-time form at runtime and show it in a window.
After cloning it and before showing it I also create a variable ‘rootFormName’ in the form and assign it a string value (the name of the window where the form later lives).
All good before I try to either show the form (forms[windowName].controller.show(window):wink: or load records in it (forms[windowName].controller.loadRecords(separateFS);).
Then I can see the following output in my console.

WARN  - Debug                      - cant parse variable 'rootFormName'
org.mozilla.javascript.EvaluatorException: missing ) in parenthetical
	at org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:114)
	at org.mozilla.javascript.DefaultErrorReporter.error(DefaultErrorReporter.java:102)
	at org.mozilla.javascript.Parser.addError(Parser.java:149)
	at org.mozilla.javascript.Parser.reportError(Parser.java:161)
	at org.mozilla.javascript.Parser.mustMatchToken(Parser.java:243)
	at org.mozilla.javascript.Parser.primaryExpr(Parser.java:2242)
	at org.mozilla.javascript.Parser.memberExpr(Parser.java:1903)
	at org.mozilla.javascript.Parser.unaryExpr(Parser.java:1750)
	at org.mozilla.javascript.Parser.mulExpr(Parser.java:1676)
	at org.mozilla.javascript.Parser.addExpr(Parser.java:1656)
	at org.mozilla.javascript.Parser.shiftExpr(Parser.java:1635)
	at org.mozilla.javascript.Parser.relExpr(Parser.java:1608)
	at org.mozilla.javascript.Parser.eqExpr(Parser.java:1561)
	at org.mozilla.javascript.Parser.bitAndExpr(Parser.java:1550)
	at org.mozilla.javascript.Parser.bitXorExpr(Parser.java:1539)
	at org.mozilla.javascript.Parser.bitOrExpr(Parser.java:1528)
	at org.mozilla.javascript.Parser.andExpr(Parser.java:1516)
	at org.mozilla.javascript.Parser.orExpr(Parser.java:1504)
	at org.mozilla.javascript.Parser.condExpr(Parser.java:1487)
	at org.mozilla.javascript.Parser.assignExpr(Parser.java:1472)
	at org.mozilla.javascript.Parser.expr(Parser.java:1459)
	at org.mozilla.javascript.Parser.statementHelper(Parser.java:1342)
	at org.mozilla.javascript.Parser.statement(Parser.java:701)
	at org.mozilla.javascript.Parser.parse(Parser.java:389)
	at org.mozilla.javascript.Parser.parse(Parser.java:320)
	at org.mozilla.javascript.Context.compileImpl(Context.java:2415)
	at org.mozilla.javascript.Context.compileString(Context.java:1393)
	at org.mozilla.javascript.Context.compileString(Context.java:1385)
	at org.mozilla.javascript.Context.evaluateString(Context.java:1230)
	at com.servoy.j2db.scripting.ScriptVariableScope.evalValue(ScriptVariableScope.java:170)
	at com.servoy.j2db.scripting.ScriptVariableScope.put(ScriptVariableScope.java:136)
	at com.servoy.j2db.scripting.ScriptVariableScope.put(ScriptVariableScope.java:75)
	at com.servoy.j2db.scripting.FormScope.createVars(FormScope.java:75)
	at com.servoy.j2db.FormController.initForJSUsage(FormController.java:3824)
	at com.servoy.j2db.FormController.initForJSUsage(FormController.java:4199)
	at com.servoy.j2db.FormController.getFormScope(FormController.java:4555)
	at com.servoy.j2db.dataprocessing.DataAdapterList.<init>(DataAdapterList.java:288)
	at com.servoy.j2db.smart.dataui.DataRenderer.createDataAdapter(DataRenderer.java:294)
	at com.servoy.j2db.smart.dataui.DataRendererFactory.placeElements(DataRendererFactory.java:388)
	at com.servoy.j2db.smart.dataui.DataRendererFactory.completeRenderers(DataRendererFactory.java:236)
	at com.servoy.j2db.FormController.createDataRenderers(FormController.java:1705)
	at com.servoy.j2db.FormController.init(FormController.java:1545)
	at com.servoy.j2db.FormManager.leaseFormPanel(FormManager.java:890)
	at com.servoy.j2db.scripting.CreationalPrototype.get(CreationalPrototype.java:172)
	at org.mozilla.javascript.ScriptableObject.getProperty(ScriptableObject.java:1641)
	at org.mozilla.javascript.ScriptRuntime.getObjectElem(ScriptRuntime.java:1399)
	at org.mozilla.javascript.ScriptRuntime.getObjectElem(ScriptRuntime.java:1378)
	at org.mozilla.javascript.gen.c884._c0(Unknown Source)
	at org.mozilla.javascript.gen.c884.call(Unknown Source)
	at org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:91)
	at org.mozilla.javascript.gen.c873._c0(Unknown Source)
	at org.mozilla.javascript.gen.c873.call(Unknown Source)
	at org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:91)
	at org.mozilla.javascript.gen.c872._c0(Unknown Source)
	at org.mozilla.javascript.gen.c872.call(Unknown Source)
	at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:65)
	at org.mozilla.javascript.gen.c869._c0(frm_doAction:36)
	at org.mozilla.javascript.gen.c869.call(frm_doAction)
	at org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:91)
	at org.mozilla.javascript.gen.c655._c0(doAction:171)
	at org.mozilla.javascript.gen.c655.call(doAction)
	at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:387)
	at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3134)
	at org.mozilla.javascript.gen.c655.call(doAction)
	at org.mozilla.javascript.JavaAdapter.doCall(JavaAdapter.java:547)
	at org.mozilla.javascript.JavaAdapter.access$0(JavaAdapter.java:532)
	at org.mozilla.javascript.JavaAdapter$1.run(JavaAdapter.java:526)
	at org.mozilla.javascript.Context.call(Context.java:591)
	at org.mozilla.javascript.ContextFactory.call(ContextFactory.java:499)
	at org.mozilla.javascript.JavaAdapter.callMethod(JavaAdapter.java:522)
	at adapter1.mouseClicked(<adapter>)
	at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$000(Unknown Source)
	at java.awt.EventQueue$1.run(Unknown Source)
	at java.awt.EventQueue$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue$2.run(Unknown Source)
	at java.awt.EventQueue$2.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)

There’s nothing in onLoad or onShow of those forms that would touch my new variable and I cannot figure out what is causing the error in the console.
Please help.

Cheers,
Maria

Hi Maria,

Can you show us the code where you create this form variable ?

ROCLASI:
Hi Maria,

Can you show us the code where you create this form variable ?

Gladly :)

var clonedMainForm = solutionModel.cloneForm(name, solutionModel.getForm(formName));	
var rootName = (rootName == null) ? name : rootName;

var newVar = solutionModel.getForm(name).newFormVariable("rootFormName", JSVariable.TEXT)
newVar.defaultValue = rootName;

That is pretty much it.
The last two lines are in a function of their own, I pass ‘name’ and ‘rootName’ as parameters to it.

Cheers,
Maria

many people seem to constantly fall into this
so i will try to explain it here once more, please look at the same/doc of the defaultValue property!

what you assign to that property is a string that is getting evalled in js

So what you do now:

var myvar = form.createVariable()
myvar.defaultValue = ‘test’

will result in that myvar will be instantiated with the evalled value of ‘test’ and then the quotes is just to make it a string, so the contents of that string is the actual javascript
so what is being done here is that the myvar value is tried to be filled in with the test variable which should also be there before it…

because in code this is what it would be:

var myvar = test;

but what you want is:

var myvar = ‘test’

so you should say that when creating the variable through the solutionModel:

var myvar = form.createVariable()
myvar.defaultValue = “‘test’”

so double quote it

it your case:

var myvar = form.createVariable()
myvar.defaultValue = “'” + rootName + “'”;

so surround the rootname with quotes

jcompagner:
many people seem to constantly fall into this
so i will try to explain it here once more, please look at the same/doc of the defaultValue property!

what you assign to that property is a string that is getting evalled in js

So what you do now:

var myvar = form.createVariable()
myvar.defaultValue = ‘test’

will result in that myvar will be instantiated with the evalled value of ‘test’ and then the quotes is just to make it a string, so the contents of that string is the actual javascript
so what is being done here is that the myvar value is tried to be filled in with the test variable which should also be there before it…

because in code this is what it would be:

var myvar = test;

but what you want is:

var myvar = ‘test’

so you should say that when creating the variable through the solutionModel:

var myvar = form.createVariable()
myvar.defaultValue = “‘test’”

so double quote it

it your case:

var myvar = form.createVariable()
myvar.defaultValue = “'” + rootName + “'”;

so surround the rootname with quotes

Awesome!
Thanks heaps, Johan. I should have looked in the doc for defaultValue, it’s all there.
Appreciate your taking time to teach us some basic wisdom :)

Cheers,
Maria

Johan,

When you search for defaultValue in the Wiki (in the Servoy 6.1 section) you find the following topics:

Variable
JSVariable
ColumnInfo
SolutionModel

In the section for JSVariable documentation is up to spec with regard to your comments on using quotes for defaultValue. However, Variable is not and that’s the first one. Same applies for SolutionModel (see newGlobalVariable).
Perhaps adjusting the documentation will help prevent people from falling into the same trap.

An issue has been created: Jira

you are right about solutionmodel.newGlobalVariable
there we can also as an extra sample place it there

With Variable: http://wiki.servoy.com/display/test61/V … faultValue
It is mentioned there pretty good.

for ColumnInfo this doesn’t apply, that value is not evalled thats just as is.

I thought that it could be confusing that the Variable section demonstrates the use of single quotes whereas the JSVariable section demonstrates the use of two pair of quotes. Wasn’t that the point of your post?

Variable:

..
For TEXT variables it can be any string surrounded with quotes, like 'some text'.
..

JSVariable:

txtVar.defaultValue = '"some text"'; // Use two pairs of quotes if you want to assing a String as default value.

yes i did change that a bit
But technically it is correct, we say it can be any string (this is more java api do remember that) but the string must be surrounded by quotes
So when i look at that form java, i know a string is just “test” and when it says the string must be surrounded by quotes i know i have to do “‘test’” because a String is already by default “”

Ok, thanks Johan!