With the cx:let element you create a new variable and assign it a value in one go. You use the variable within the cx:let content.
An example:
<cx:let name="s" value="This is a text">
... the variable $s is available up until the closing tag ...
</cx:let>
For a description of valid variable names see variables.
Shorten long key-paths
Besides creating variables the cx:let element is also useful to shorten long key-paths used frequently, like in:
<cx:let name="e" value="$activity.toEmployee">
... the variable $e contains the employee object ...
</cx:let>
Change the type
Often a constant value can be used immediately. However, sometimes an extra operation is nescessary to obtain the correct Type.
In these cases the cx:let element is useful as well.
As in the following example wherein a string is changed into a list:
<cx:let name="l" value="(a,b,c)" invoke="propertyList">
... $l contains a list value with elements a, b, and c ...
</cx:let>
The key "propertyList" passed through the invoke attribute in the previous example is invoked on the constant string value "(a, b, c)". De same result can be obtained in a more elaborate way:
<cx:let name="s" value="(a,b,c)">
<cx:let name="l" value="$s.propertyList">
... $l contains a list value with elements a, b, and c ...
</cx:let>
</cx:let>
Attributes
The following table contains the available attributes for the cx:let element.
The obligatory attributes are bold:
condition
By using cx:let it is also possible to assign one or the other value to a variable depending a condition:
<cx:let name="s" condition="x > 0" iftrue="Yes" iffalse="No">
<cx:write value="$s"/>.
</cx:let>
invoke
By using invoke it is possible to process the value before it is assigned to the variable.
Fetching datanodes
Instead of using cx:fetch use the following cx:let code to fetch a list of datanodes:
<cx:let name="dnc" value="CRDataNodeCache" invoke="namedClass.cache">
<cx:let name="products" value="$dnc" invoke="Product">
...
</cx:let>
</cx:let>
In the previous example the items for the table products is fetched and available in the list products.
Remarks
After the closing tag </cx:let> the variable retains its previous value (often nil), unless the keep attribute is used.