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. Variable insertion is supported in some functions' configuration settings, like https://infozone.atlassian.net/wiki/spaces/DAZ/pages/7897286 and https://infozone.atlassian.net/wiki/spaces/DAZ/pages/7798876.
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 '@' ).
Scopes
Usage Engine allows you to perform Variable Insertion using the following scopes:
payload
meta
sharedStore
The table below provides an overview of how to use these scopes, accompanied by 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:
Returns 'undefined' instead of throwing an error when accessing non-existent paths
Returns full object (payload) for ${payload}
Returns a JSON representation of objects instead of [Object object]
@{scope} will result in an object
Caution!
You must not use special characters, such as the dollar sign ($), ampersand (&), at sign (@), or curly braces ({ }), in field names when you use interpolation, because these characters are reserved for interpolation and cause errors or unexpected behavior if included.
For example, ${payload.myValue} works as expected, but ${payload.my$value} does not.
Example - Nested data structure
If you have a nested data structure in payload.foo and want to preserve the structure without transforming it into a string, then you must use @{payload}.foo} instead of ${payload.foo}.
Variable insertion with scopes
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.
Note!
| // Payload = {
allFruits:
{
banana: 1,
apple: 2,
orange: 3
},
myFruit: 'apple'
} To access or, if you want to use nested Variable Insertion, you can use square brackets '[]'
| |
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 Note!
| For example, if you want to try to read from an Amazon S3 forwarder function using a Script function: meta.fileName = "myFile"
log.info(meta.fileName);
await push(payload);And, do variable insertion on the filename: |
sharedStore
| Data that is currently stored in the shared store. The The See https://infozone.atlassian.net/wiki/spaces/DAZ/pages/7897286 for more information. | sharedStore:
1 = 5.csv
2 = 10.csv
anotherProperty = {
first:
{
second: "third"
}
}
${sharedStore[1]} ----> 5.csv
// SharedStore = { file1: 'my-first-file.csv', file2: 'my-second-file.csv'} |