Skip to main content

Version: 21.11

Expressions

Many properties in the Narrative expect a Boolean value. While these values can be static such as true or false, they can also be evaluated at runtime based on application and Txn data.

info

You can use an Expression anywhere the Narrative expects a Boolean value.

Expression evaluation

Each expression is treated as a Groovy G-String. Anything that can be done with a G-String can be done in an Expression.

An expression is expected to evaluate to the String "true" or the String "false", which will be interpreted by the Narrator as the boolean values true and false, respectively.

For example, the following expression evaluates as "true", which in turn is treated as Boolean true.

${ 'Foobar'.startsWith('Foo') }

Parsing JSON

To assist with parsing JSON data, an instance of JsonSlurper is passed into each Expression, and can be used to parse and access data from JSON strings. The name of this object is jsonSlurper.

For example, say you have a Txn Property which contains the following JSON:

{
"idvResult": "PASSED"
}

Then, you could retrieve and verify the idvResult value like this:

${ jsonSlurper.parseText( txn.propertyMap.get('myJsonProp') )['idvResult'] == 'PASSED' }

What data is available to expressions?

Expressions have access to raw application data Objects, as well as Objects that can be used to retrieve additional data. The available objects are:

All Expressions have access to exactly the same data, meaning an Expression evaluates to the same value, regardless of where it's run.

Txn data

Expressions have access to the current Txn, which can be used to access standard Txn data.

Example: Txn data
${ txn.userSaved }

Domain model data

Any domain model data configured with a Narrative will be passed into an Expression and made available via the data variable. The data in this variable will depend entirely on the project. The data variable is an instance of Map<String, Object>.

Example: Domain model data
${ data.get('applicants').getPrimaryApplicant().age() >= 18 }

Properties

A PropertyQuery object is passed into every expression as a variable called propertyQuery. You can use this variable the same way you use a new instance of this Class.

Example: Properties
${ propertyQuery().setName('Saved Email').setTxn(txn).getValue() != '' }

In addition to propertyQuery, a helper has been added specifically to retrieve Form Properties.

Example: Properties helper
// Instead of this ...
${ propertyQuery().setFormCode(txn.formCode).setName("My Property").getValue() }
// You can write this:
${ formProp:My Property }

Form XML

note

We recommend that you use Domain Model Data, Data Extracts, or Properties over XML/XPaths. Newer Journey Manager (JM) applications tend to use XML exclusively for storage and transport between JM and Maestro. The format of the XML is dynamic; direct use of XPath is brittle and couples your Narrative to your Form.

To assist in retrieving values from the Txn Form XML, a Path object containing the form XML is passed into every Expression. This variable is named xmlPath and can be used the same way you use a Path object.

Example: Form XML
${ xmlPath.val('//Foo') == "bar" }