Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

In this Page

Table of Contents
maxLevel2
excludeAdditional Resources|Related Links|Related Information

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.

...

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.

Note

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 '='. 

...

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:


Paste code macro
languagejson
titleSample output preview
[
  {
    "value": {
      "_snaptype_datetime": "2018-04-27T20:03:58.453 UTC"
    },
    "sub-expression": {
      "0: Date": [
        {
          "_snaptype_scope": [
            "parse",
            "now",
            "UTC"
          ]
        }
      ],
      "1: (1,2,3)": [
        {
          "_snaptype_arguments": {
            "ignored": 3
          }
        }
      ],
      "2: .now": [
        {
          "_snaptype_datetime": "2018-04-27T20:03:58.453 UTC"
        }
      ]
    }
  }
]


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:

Note

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.

Note

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.

Note

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:

Code Block
"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":

Code Block
_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:

Code Block
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:

Code Block
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:

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