Parameters and Fields

Overview

The use of parameters (_parameters) and fields ($fields) varies depending on where you are within the SnapLogic Elastic Integration Platform and the type of property in which you use them. The following sections explain how they can be used.

Important: Parameters are string values.

Expression Properties in Snaps

Within properties that can take expressions:

  • Both _parameters and $fields are available.

Exceptions:

  • The database Insert/Table List Snaps do not allow input fields to be referenced; only Pipeline parameters are available.
  • $fields cannot be used in binary Snaps, only in Document Snaps. A common error is trying to reference an upstream Snap $field in a File Writer.

JSONPath Properties in Snaps

  • Fields are available.
  • Pipeline parameters can be accessed in expression components in the path. For example, to access a field that is specified by a Pipeline parameter you can write: $.foo.bar[(_myParam)]
  • Pipeline parameters cannot be mixed into the result of a JSON-path query.

Example:

To access a field specified by a pipeline parameter:

$.foo.bar[(_myParam)]

Velocity Templates in Generator Snaps

Both parameters and fields are available, however, the syntax is different since you're working in the Velocity Template Language.

Accessing Pipeline Parameters:

Pipeline parameters are accessed using ${_parameter} syntax:

[
  {
    "remove_user" : ${_user}
  }
]
Note: Field references cannot use expression language or JSON path features in Velocity templates.

Dynamic Database Queries

$.eval() can be used to either substitute Pipeline parameters or execute functions without having to use an expression toggle (=).

Examples:

  • Substitute Pipeline parameters:
    CUSTOMER_ID = $.eval(_parameter)
  • Execute functions:
    $.eval(Date.now())

SQL Substitution

When using field and parameter references in SQL statements:

  • Only simple fields will work; spaces or special characters (including $) cannot be in the field name unless they are treated as a string, such as $['Home address'].
  • To use a parameter in a SQL select statement, you can use a Mapper Snap before the SQL Snap to turn the parameter into an input field, which can then be used in the where clause using the $param syntax.

Field with Special Characters:

$['Home address']

Using Parameters in SQL:

  1. Add a Mapper Snap before the SQL Snap
  2. Map the pipeline parameter to an input field
  3. Reference the field in the SQL where clause using $param syntax

Script Snap

In the Script Snap, Pipeline parameters are available by using the following syntax:

scriptVarName = $_whateverPipelineParamName

This allows you to access pipeline parameter values and assign them to script variables for use in your script logic.

Summary Table

Context Parameters Fields
Expression Properties _parameter $field (Document Snaps only)
JSONPath Properties $.path[(_parameter)] $.field
Velocity Templates ${_parameter} Available (limited syntax)
Dynamic Database Queries $.eval(_parameter) $.eval($field)
SQL Substitution Via Mapper to field $field (simple names only)
Script Snap $_parameter Standard script access

Best Practices

  • Use meaningful names: Choose descriptive parameter and field names that clearly indicate their purpose.
  • Remember parameter types: Pipeline parameters are always strings, so convert them if you need numeric values.
  • Mind the context: Different Snap types and property types have different syntax requirements for accessing parameters and fields.
  • Special characters: When field names contain spaces or special characters, use bracket notation: $['field name']
  • Binary vs Document: Remember that $fields only work in Document Snaps, not binary Snaps.
  • SQL workaround: Use a Mapper Snap to convert parameters to fields when needed in SQL statements.