/
Variable insertion

Variable insertion

Variable insertion (Interpolation) is a way to dynamically modify a string expression or object at runtime. 

Usage Engine uses curly brackets to indicate that a Variable Insertion will take place. The variable insertion is supported in some functions' configuration settings and also within Script and Script Aggregator functions.

Within the curly brackets, you can access variables that belong to different scopes and use them to generate a dynamically changed output at runtime. Depending on what you want to achieve or manipulate, the output from variable insertion can be a string, (if prefixed by '$') or an object( if prefixed by '@' ).

Example - Variable insertion

In this example, we will send the same message to different customers, and insert the customer name in the message at runtime.

Workflow

Script code block

payload.customer_name = "Johnny"; payload.full_message = `Hello ${payload.customer_name}. You have received a new mail.`; await push(payload);

Function configuration for Email notification using variable insertion

When you run this code, the intended recipient (Johnny in this case) will see an email with the following content:

Hello Johnny. You have received a new mail.

 

Scopes

Usage Engine allows you to perform Variable Insertion using the following scopes only.

  • payload

  • meta

  • deploy

  • sharedStore

The table below describes how to use these scopes with a few examples. You can also perform nested Variable Insertion using the same or different scopes.

Note!

While using '$' or '@', note the following:

  • ${scope} will result in a string. ${scope} behaves like a JavaScript template Variable Insertion with the following exceptions: 

  • @{scope} will result in an object

Example
If you have a nested data structure in payload.foo, and you want to keep the structure and not transform it into a string, then you must use @{payload.foo} instead of ${payload.foo}.

 

Variable insertion with scopes