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 fields 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 '@' ).


Consider a scenario where you want to send the same message to different customers and insert the customer name in the message at runtime.

Script code block
payload.customer_name = "Johnny";

payload.full_message = `Hello ${payload.customer_name}. You have received a new mail.`;

await push(payload);

And this is what the Variable Insertion in the Email Notification Function looks like:

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.


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

  • payload
  • meta
  • deploy
  • sharedStore

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

$ or @

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

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

    • Returns 'undefined' instead of throwing an error when accessing non-existing paths
    • Returns full object (payload) for ${payload}
    • Returns a JSON representation of objects instead of [Object object]
  • @{scope} will result in an object

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

Variable Insertion with Scopes 

 You can use Variable Insertion using the following scopes/variables/objects only:



You can perform Variable Insertion on any data from the current record.
The payload scopes cover any content that is sent from one node to the next.

Payload type variable insertion can be used to address the data flowing through the stream.


The Payload scope is not accessible for Collector Functions.

// Payload = { 
    banana: 1, 
    apple: 2, 
    orange: 3 
  myFruit: 'apple' 

To access apple you can use Variable Insertion like: ${payload.myFruit}


if you want to use nested Variable Insertion, you can use square brackets '[]'

${payload.allFruits[apple]} ---> The result will be 2


Meta covers additional information that gives further context to the data (metadata). 

meta type Variable Insertion is designated to process the accompanying metadata. 

You can use Variable Insertion using any data from the current record's metadata. You can use meta with a Processor or a Forwarder Function.


The Meta scope is not accessible for Collector Functions.

For example, if you want to try to read from an Amazon S3 Forwarder Function using a Script Function:

meta.fileName = "myFile";
await push(payload);

And, do Variable Insertion on the filename:

Once you run the stream, you will find the files in S3 Forwarder with the following format:
myFile<count of the file>_<timestamp>.csv


You can use Variable Insertion using replicaNumber and lastReplicaNumber properties only.

When running a stream with multiple replicas, the first instance would be identified as the first replica. This is represented in the deploy scope as deploy.replicaNumber = 1 

Each running replica instance will have a different replica identification number.

The lastReplicaNumber variable will be the same in all replicas, identifying how many replicas running in total. For example, a stream configured to run 3 replicas would have the lastReplicaNumber set to 3 in all running instances. 

For more information about replicas, see Performance and scalability.

For example,

To access the second instance of a replica with a total of three instances running:

replicaNumber will be 2

lastReplicaNumber will be 3

You can use Variable Insertion like:

${deploy.replicaNumber} ----> 2

//or, nested Variable Insertion:



Data that is currently stored in the shared store.

The sharedStore property allows you to define your variable and use it across different streams.

The sharedStore scope is loaded during the start of the stream and the content does not change during the execution.  So if you have done any changes to the sharedStore variable that will take effect in the subsequent execution only.

Refer Script for more information.

      1 = 5.csv
      2 = 10.csv
      anotherProperty = { 
          second: "third" 

${sharedStore[1]} ----> 5.csv
${sharedStore[${sharedStore.replicaNumber}]} ----> 5.csv

// SharedStore = { file1: 'my-first-file.csv', file2: 'my-second-file.csv'} 

---> 'my-first-file.csv' for replica 1
---> 'my-second-file.csv' for replica 2


 S3 Bucket Dynamic Naming

Variable Insertion can be used conveniently to designate dynamic names for files that are read from S3 buckets, for example, the time and date of the collection. Data collected from the buckets can come with their metadata called “CollectionTime”.

Defining the filenames is done by specifying

Filename: Collected$(meta.collectionTime). 

As a result, the system will generate file names during execution that utilize the data. Data collected at “2022-07-13To7:26:44.729Z” will be collected in a file called Collected.2022-07-13T07:26:44:729Z. 

 URL Variable Insertion

URL Variable insertion is useful when setting up REST API connections from authentication servers. 

When working with Salesforce connections this is the answer that is received from the server: 


      "access_token": "00D7Q000006yDaM!ARgAQHJ.NsUJefLJ0JTfuD2LGrerx7Ww8k8IOcflOaRWr5VBmXytEgcluwjRaFSAL7z_vI_NnmsHV2SRYMEomOJ2nXF_kez_"

     "instance_url": ""

      "id": ""

      "token_type": "Bearer"

      "issued_at": "1657697592923"

      "signature": "yRtGqYfqWx/oSx55De6UGsI0MXWDuUL5NKBXE5D2GnI="


To perform a POST action from the HTTP Client the following can be defined as an URL: 


This will result in the following URL when the stream executes:
 SQL Query Variable Insertion

If concrete information is required to perform a SQL query, for example, a customer Id, and is coming from incoming data, then variable data can be used to extract the data. In this situation this example query can be used to generate the query: 

select username from account where key=${payload.customerId}

See Variable Insertion using HTTP Client for a few examples of variable substitution using HTTP Client.