Variable Insertion (Interpolation) is a way to dynamically modify a string expression , or object at runtime.
Usage Engine use 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 '@' ).
Let's have a look at a simple example:
Info | |||||||
---|---|---|---|---|---|---|---|
| |||||||
Let's consider Consider a scenario where you want to send the same message to different customers and insert the customer name in the message at the runtime.
And , this is what the Variable Insertion in the Email Notification Function looks like:
|
...
- payload
- meta
- deploy
- sharedStore
Refer to the 7861678 below table below to know how to use these scopes and some examples for understandingwith a few examples. You can also perform nested Variable Insertion using the same or different scopes.
...
Info | |||||
---|---|---|---|---|---|
| |||||
While using '$' or '@', you need to remember note the following:
For example:Example |
Variable Insertion with Scopes Anchor table table
table | |
table |
...
You can use Variable Insertion using the following scopes/variables/objects only:
Scope | Explanation | Example | |||||||
---|---|---|---|---|---|---|---|---|---|
You can perform Variable Insertion on any data from the current record.
|
To access or, if you want to use nested Variable Insertion, you can use square brackets '[]' ${payload.allFruits[apple]} ---> The result will be 2 | ||||||||
meta | Meta covers additional information that gives further context to the data (metadata).
You can use Variable Insertion using any data from the current record's metadata. You can use
| For example, If if you want to try to read from an Amazon S3 Forwarder Function using a Script Function:
And, do Variable Insertion on the filename: Once you run the stream, you will find the files in S3 Forwarder with the following format: | |||||||
deploy | 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 The 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:
You can use Variable Insertion like:
| |||||||
sharedStore | Data that is currently stored in the shared store. The The Refer Script for more information. |
|
...
Examples
...
Expand | ||
---|---|---|
| ||
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. |
...