Declares and defines a variable to store a value that you can reference throughout the solution.
Remarks
You can only declare let
elements as the children of a declarations trait. If you include one, the
declarations
trait must be the first child of its parent in the XML
hierarchy.
When setting up a helper variable, make sure that the shape
field and the
data type of the value that the query in the value
property returns match. If
shape="scalar"
, value
's return value must not have more
than one row nor more than one
column.
Figure 237. The scalarLet
variable stores the text input in the
textbox
controls, joined with a comma
If shape="record"
, value
's return value can have more than
one column, but no more than one row. The example below uses the value of the
recordLet
variable as the selectedKey
of a
dropdown
with a record-shape keyMap
property.
... <declarations> <let id="recordLet"shape="record" value='{TABLE pitter, patter (boxQ.text, boxR.text)}'
/> ... </declarations> <textbox id="boxQ" label="Enter a word or two" text=""/> <textbox id="boxR" label="Enter some more text" text=""/> ... <dropdown choices='{TABLE pitter, patter, potter (boxQ.text, boxR.text, "Goo!"; "axolotl", "moxie", "Boo!")}' keyMap='{SELECT pitter, patter}' textMap='{potter}'selectedKey='{SELECT recordLet.pitter pitter,
recordLet.patter patter}'
/> ...
Figure 238. The dropdown
control in the screenshot has a record
type key stored in fields of the recordLet
variable
If shape="table"
, value
's return value may have one or more
rows and one or more columns as well. You can reference a let
with a
table-shape value
in the FROM
-clause of a
SELECT
statement as if it were a database table. The example below puts the
value of the tableLet
variable into the recordset
property
of a table
control.
... <declarations> ... <let id="tableLet"shape="table" value='{TABLE patter(boxQ.text;boxR.text)
}'/> </declarations> ... <textbox id="boxQ" label="Enter a word or two" text=""/> <textbox id="boxR" label="Enter some more text" text=""/> <table id="tableK"recordset='{SELECT d.patter FROM tableLet d}'
record="f"> <row> <cell> <textview text='{f.patter}'/> </cell> </row> </table> ...
The variable you declare in a let
is accessible in the naming scope of its
closest ancestor that has an id
, using the
controlId
.
letId
syntax. If none of the variable definition's ancestors have an id
, the
let
is in the naming scope defined by the form
element.
Because the value of a variable is defined by a query expression, and query
expressions are re-evaluated whenever their dependencies change, the value of the variables
you declare with let
can be dynamic.
Unlike webform controls, let
elements MUST have an id
field,
because the variables that they declare need to be referenced elsewhere in the solution.
Sample
... <declarations> <let id="scalarLet" shape="scalar" value='{boxR.text||" , "||boxQ.text }'/> <let id="recordLet" shape="record" value='{TABLE pitter, patte (boxQ.text, boxR.text)}'/> <let id="tableLet" shape="table" value='{TABLE patter (boxQ.text; boxR.text)}'/> </declarations> <textbox id="boxQ" label="Enter a word or two" text=""/> <textbox id="boxR" label="Enter some more text" text=""/> <textview label="You entered: " text='{scalarLet}'/> <dropdown choices='{TABLE pitter, patter, potter (boxQ.text, boxR.text, "Goo!"; "axolotl", "moxie", "Boo!")}' keyMap='{SELECT pitter, patter}' textMap='{potter}' selectedKey='{SELECT recordLet.pitter pitter, recordLet.patter patter}'/> <table id="tableK" recordset='{SELECT d.patter FROM tableLet d}' record="f"> <row> <cell> <textview text='{f.patter}'/> </cell> </row> </table> ...
All
possible types of let
elements declared inside a
declarations
trait
A workflow script running in the Mobilengine Cloud would access the submission of the webform above in the format below:
{... boxQ: {text: "giant"}, boxR: {text: "shrimp"}, selectedKey: {pitter: "giant", patter: "shrimp"}, selectedText: "Goo!", selectedValue: {pitter: "giant", patter: "shrimp", potter: "Goo!"}, scalarLet: "shrimp , giant", recordLet: {pitter: "giant", patter: "shrimp"}, tableLet: [{patter: "giant"}, {patter: "shrimp"}], ...}
See the workflow script reference guide for more details on data type mapping.