To use JavaScript in Usage Engine, there are some mandatory variables and APIs that you require.
Variables/Functions | Description | Examples |
---|---|---|
audit | To control the custom user audit function. The supported types are:
Syntaxaudit.count(key);
Syntaxaudit.sum(key,value);
Syntaxaudit.set(key,value); | Example - audit.set
Example - audit.sum
Example - audit.count
|
| An object that contains logging functionality for the severity levels: info, warning, and error.
Note
Note! Currently, the Console object in JavaScript, which provides access to the browser's debugging console, is disabled. | Example - log variable
|
| The | Example - Payload variable
|
| The The following metadata is accessible using the Script Flush tab:
| Example - using S3 Forwarder If you choose to add properties to In the Script Function, const moment = require("moment"); if (!meta.simDate) { meta.simDate = moment(new Date()).format('YYYYMMDD'); } In the Amazon S3 forwarder, add this in the Filename field: For more information, please see Configuring Dynamic Naming in Fields. |
| To send data downstream. You need to invoke this Function using | To send data to the next Function(s) in the stream. Example - push variable
|
| This is to keep the state across records. The state is only available during one stream execution. The information stored in the The
Note! Refer to https://infozone.atlassian.net/wiki/x/iod4 for tips avoid losing memory in case of stream execution or system downtime issues. | Example - node
Example - stream variable
|
| These three operations functions as a key-value store. The key must be a string. Value can be of any type, for example: string, number, date, JSON object, and array.
Note! Sets the value for a key for the defined duration. The TTL parameter is optional and the default value is 30 days, that is, 2 592 000 seconds. A key can be stored for a maximum of 60 days (5 184 000 seconds), however, this duration gets extended every time Note! If a value exceeding the maximum limit is entered, the value is automatically set to the designed maximum.
| Example - store variable
Example:
Example:
|
| With shared persistent storage, streams can access the same data. For example, one stream writes data to the shared persistent storage that can be used by one or more streams. The key must be a string. Value can be of any type, for example, string, number, date, JSON object, and array. Note! Streams sharing data must belong to the same solution. You must use the
Note! If a value exceeding the maximum limit is entered, the value is automatically set to the designed maximum.
| Example - shared storage
Example - shared storage
Example - shared storage
|
Error message example
This simplistic example shows the log when the keyword "payload" is spelled with a capital 'P'. The following example uses the Summarize Monthly Usage Data example stream.