Using Expressions

In this Page

Overview

Expressions are available across multiple Snaps. If the Snap exposes the expressions functionality for a property, then the  icon appears in front of the text box of the property.

 
Only Snap properties in the Settings category can currently provide expression functionality. 

Any field preceded with an equal sign (=) button can handle an expression if that button is toggled on.

Click the down arrow within the field to see the list of functions and properties available.


Type within that field to filter the functions displayed.


Filtering only works on subitems that would be part of the expression, like pipe.label. For function groups that are not literally included in the expression, like Array, filtering will not show the subitems since Array is not used in the expression.

Click the Expand Editor button within the menu to have a larger work area to create your expressions.

As you create expressions, they are validated in real-time for syntax and spelling errors and to provide output previews. See Dynamic Validation for details.

Expression language cannot be used in Account settings.

Dynamic Validation of Expressions and Output Preview

Expressions are dynamically evaluated at a sub-expression level as they are typed and an output preview shown for each part of the expression - object, method, and arguments. This is particularly useful in debugging complex expressions as it can be difficult to see the results of sub-expressions within an expression. Preview results of the sub-expression are shown within the yellow curly brace '{' and the result of the whole expression within the green equals sign '='. 

To see the result of a sub-expression click on the sub-expression and its evaluation will be shown in the Output Preview pop-up, with the sub-expression highlighted in bold font. For example, consider an object 'msg' containing the string "Hello, World". An expression is to be built to convert this string to lower case: $msg.toLowerCase() 

When the Snap is validated, the expression is also dynamically validated, notice that $msg is highlighted in bold font and its result is shown after the yellow curly brace:

When the cursor is moved to the second part of the expression - the method, toLowerCase() in this example, the final result of the expression is shown:

Expression Output Preview - Suggestions and Validation

The final output preview of an expression is shown in parts, one for each block in the expression. For example, the expression Date.Now(1,2,3) will have the following output preview:


The expression's evaluation happens in real time, as you start typing the expression SnapLogic starts referencing the expression library and show's suggestions accordingly in the Output Preview pop-up:

When an object has been typed, it then suggests the methods within that object:

When arguments are entered, the expression is validated and a response shown in the Output Preview pop-up. The Expression Builder window can be opened by clicking on the arrow icon in the Output Preview pop-up:

To enable an expression's output preview, the Snap must be validated to enable the expression's output preview.

Example

The File Writer Snap provides the ability to toggle the filename into an expression by selecting the equals icon (left of the property box). The content of the text box is interpreted as an expression once the toggle is on.

The value/suggest bubble is disabled once the toggle is on. It can be re-enabled by setting the toggle to off.

An example for an expression would be: '/out' + Date.now() + '.json'
This would insert the current date as part of the filename.

An expression has to conform to the JavaScript standard, in such that a string that is part of the expression has to be enquoted.

Accessing Pipeline Parameters

Parameters allow a pipeline to be reused in multiple situations. For example, a File Writer Snap can be configured to write to a file path specified by a parameter, which allows the same pipeline to write to different files. The parameters for a pipeline can be defined by using the Edit Pipeline properties dialog. The name of each parameter must only contain alpha-numeric characters and the value will be converted to a string. The value for a parameter as defined in the pipeline properties dialog is treated as the default when running the pipeline in Designer. Parameters can also be passed to a pipeline by a Task or the ForEach Snap. Any parameters that are not passed down from the Task or Snap will use the defaults specified in the properties dialog.

To access a pipeline parameter from the expression language, you must prefix the parameter name with an underscore. For example, given the following parameters:

 KeyValue
 firstName  Bob
 numValue 12
 path $.age

 The "firstName" parameter can then be accessed using _firstName, as in:

"Hello, " + _firstName  // result: Hello, Bob

Since the value of a parameter is always a string, you'll need to convert any string to numeric values before operating on them. For example, simply adding two to the "numValue" parameter will append the character "2" to "12" and yield "122":

_numValue + 2   // result: "122"

Instead, you need to use the parseInt/parseFloat functions to parse the string into a value and then add two to it:

parseInt(_numValue) + 2   // result: 14

If you need to parameterize your pipeline with an expression, you can use the eval() function to evaluate an expression stored in a string.  For example, to read the document field specified by the "path" parameter, you can use:

eval(_path)   // result: <the value of the "age" field in the current document>

Accessing Input View Variables as Part of Expressions

An input view schema attribute can be used as part of the expression by using the dollar sign ($) prefix.

Example

The REST Put Snap provides a URL. The URL can be toggled into an expression and the expressions could be created by dynamically substituting the variables from an input view, such as:

'http://someplace:someport/somepart/' + $inputvar + '/somemoreparts'