# Cannot parse variable

**URL:** <https://forum.servoy.com/t/cannot-parse-variable/16147>\
**Category:** Classic Servoy\
**Created:** [July 6, 2012, 4:25am UTC](https://forum.servoy.com/t/cannot-parse-variable/16147 "2012-07-06T04:25:04Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![maria](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@maria](https://forum.servoy.com/u/maria)\
**Post date:** [July 6, 2012, 4:25am UTC](https://forum.servoy.com/t/cannot-parse-variable/16147/1 "2012-07-06T04:25:04Z")

</div>

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:]( "Shocked")  
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)😉 or load records in it (forms[windowName].controller.loadRecords(separateFS);).  
Then I can see the following output in my console.

```auto
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

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [July 6, 2012, 6:28am UTC](https://forum.servoy.com/t/cannot-parse-variable/16147/2 "2012-07-06T06:28:42Z")

</div>

Hi Maria,

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

---

<div class="post-metadata">

**Author:** ![maria](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@maria](https://forum.servoy.com/u/maria)\
**Post date:** [July 10, 2012, 6:43am UTC](https://forum.servoy.com/t/cannot-parse-variable/16147/3 "2012-07-10T06:43:46Z")

</div>

> ROCLASI:  
> Hi Maria,
> 
> Can you show us the code where you create this form variable ?

Gladly ![:)]( "Smile")

```auto
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

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [July 10, 2012, 3:06pm UTC](https://forum.servoy.com/t/cannot-parse-variable/16147/4 "2012-07-10T15:06:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![maria](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@maria](https://forum.servoy.com/u/maria)\
**Post date:** [July 11, 2012, 4:09am UTC](https://forum.servoy.com/t/cannot-parse-variable/16147/5 "2012-07-11T04:09:17Z")

</div>

> 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 ![:)]( "Smile")

Cheers,  
Maria

---

<div class="post-metadata">

**Author:** ![omar](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@omar](https://forum.servoy.com/u/omar)\
**Post date:** [July 11, 2012, 11:33am UTC](https://forum.servoy.com/t/cannot-parse-variable/16147/6 "2012-07-11T11:33:09Z")

</div>

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](https://support.servoy.com/browse/SVY-2663)

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [July 11, 2012, 12:06pm UTC](https://forum.servoy.com/t/cannot-parse-variable/16147/7 "2012-07-11T12:06:19Z")

</div>

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](http://wiki.servoy.com/display/test61/Variable#Variable-defaultValue)  
It is mentioned there pretty good.

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

---

<div class="post-metadata">

**Author:** ![omar](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@omar](https://forum.servoy.com/u/omar)\
**Post date:** [July 11, 2012, 12:42pm UTC](https://forum.servoy.com/t/cannot-parse-variable/16147/8 "2012-07-11T12:42:40Z")

</div>

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:

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

```

JSVariable:

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

```

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [July 12, 2012, 8:55am UTC](https://forum.servoy.com/t/cannot-parse-variable/16147/9 "2012-07-12T08:55:07Z")

</div>

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 “”

---

<div class="post-metadata">

**Author:** ![omar](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@omar](https://forum.servoy.com/u/omar)\
**Post date:** [July 12, 2012, 9:08am UTC](https://forum.servoy.com/t/cannot-parse-variable/16147/10 "2012-07-12T09:08:30Z")

</div>

Ok, thanks Johan!
