Supported Variables/APIs

To use JavaScript in Usage Engine, there are some mandatory variables and APIs that you require.

Variables/Functions

Description

Examples

Variables/Functions

Description

Examples

audit

To control the custom user audit function. The supported types are:

  • count:  Increments the string key value with 1

Syntax
audit.count(key);
  • sum: Sums up the total amount

Syntax
audit.sum(key,value);
  • set: Sets an input value. Data entry using the set function can be used with any data type. The output of the sum function will show the accumulated amount. 

Syntax
audit.set(key,value);

 

 

Example - audit.set

audit.set('Collection 1', JSON.stringify(object)): – This audit function can be used to enter any string value and save it to a specified key. 

 

Example - audit.sum

audit.sum('KEY_NAME', payload.fieldName): - This function is useful when presenting amounts of data that is to be saved or forwarded to a destination source.

 

Example - audit.count

audit.count('Tracking-Records-Changes'): - This function can be issued to increase the count of tracked records or a collection of data after an audit review. 

 

log

An object that contains logging functionality for the severity levels: info, warning, and error.

log.info("foo"); - Logs something to the Usage Engine log. See Logs.

 

 

 

payload

The payload variable contains all the information of the current record/object. 

 

meta

The meta variable provides generic information (metadata) about a payload (a record). It summarizes basic information about data, making it easier to find and work with specific instances of data.

Refer to Amazon S3 | AmazonS3 S3metadata for more details about metadata that is accessible from the Transform tab.

Refer to https://infozone.atlassian.net/wiki/x/E4HFF for more details about the metadata that applies to the Data aggregator.

The following metadata is accessible using the Script Flush tab:

  • lastCall: A boolean flag set to true for the final transaction. lastCall can be used to create a summary or audit for the processed data at the final transaction.

    To initiate action(s) triggered by the recent transaction:

     

push(<event>)

To send data downstream. You need to invoke this Function using await syntax.

To send data to the next Function(s) in the stream.

 

state

This is to keep the state across records. The state is only available during one stream execution. The information stored in the state variable is not persisted between executions and is cleared at the end of each stream execution.

The state variable contains two scopes:

  • node: To save the state locally for this Function. 

  • stream:  To save the state globally for the stream. 

 

 

 

store

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.

You need to invoke this Function using await syntax:

  • get: To get a value

  • set: To set a value of a key 

    Syntax


    And, to set the duration (in seconds) of how long the key is stored.

    Syntax

     

 

 

  • del: To delete a value

    Syntax

 

 

 

 

sharedStore

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.

 

You must use the await syntax for the Function:

  • sharedStore.get: To get a value.

    Syntax

     

  • sharedStore.set: To set a value of a key and the duration (in seconds) of how long the key is stored. 


    Syntax


    And, to set the duration (in seconds) of how long the key is stored.

    Syntax




 

 

  • sharedStore.del: To delete a value.


    Syntax

 

 

 

 

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.

 

Â