Variables

The Mobilengine form language allows helper variable declaration inside the markup. In the declarations trait, you can declare one or more let elements to essentially give a name to a specific data-binding query expression.

There is no restriction on the data type of the value that you store in a variable.

You can reuse the value of the named query expression anywhere in the form that you declare the let in, without having to enter the query again.

...
<declarations>
...
<let id="letNolo" shape="scalar" value='{"SPAM!"}'/>
</declarations>
<textbox label="I'll have some"
  text='{letNolo}'/>
<textview label="Lovely"
  text='{letNolo}'/>
<textview label="Have you got anything without"
  text='{letNolo}'/>
...
Reusing the value of the let in the form

Figure 223. Reusing the value of the let in the form


If the named query expression is a reference table query, storing its return value in a variable contributes to performance optimization, because the return value of the server query will be cached in the variable.

...
<declarations>
  <let id="letYolo"
    shape="table"
    value='{SELECT a.index, a.words, a.more_words
          FROM randomWord a}'/>
</declarations>
...
<textview text='{SELECT GROUP_CONCAT(b.words, "%")
                FROM letYolo b}'/>
...
The data-binding expression in the textview is evaluated without querying the server

Figure 224. The data-binding expression in the textview is evaluated without querying the server


Storing a reference table query in a let can serve as a workaround to combine a server-side and a browser-side query and overcome the data-binding execution context limitation that the server can only access scalar-value browser-side query results.