Contact Us 1-800-596-4880

Record Variable

Mule runtime engine version 3.8 reached its End of Life on November 16, 2021. For more information, contact your Customer Success Manager to determine how to migrate to the latest Mule version.

Enterprise, CloudHub

With batch processing comes the ability to set, remove, and reference variables associated to individual records. Serialized and persisting only through the Process phase, a record variable stores information at the record level, rather than the flow or session level. For example, you can use recordVars to capture whether or not a customer contact – as a record – already exists in a database.

capture_customer_contact

Prerequisites

This document assumes that you are familiar with Anypoint Studio and have reviewed the overview and basic anatomy of Batch Processing.

Setting a Record Variable

During the Process phase, the record is the message payload. As such, you may wish to use MEL expressions in message processors within a batch step to replace or manipulate the payload during processing. However, where you don’t want to touch the payload, you can use record variables to persist information between batch steps. There are two ways you can set record variables within batch steps in a batch job:

  • Set a Record Variable message processor in one of the batch steps in your batch job, setting the Operation to Set Record Variable. View full details of the message processor’s attributes.

    Studio Visual Editor

    record_variable

    XML Editor

    <batch:set-record-variable doc:name="Record Variable" variableName="age" value="#[payload.age]"/>
  • Use a MEL expression to add a new recordVars to records within a batch step.

#[recordVars['key']]

Removing a Record Variable

During the Process phase of batch processing, use the Record Variable message processor to remove an existing recordVars from records, setting the Operation to Remove Record Variable. View full details of the message processor’s attributes.

Studio Visual Editor

remove_rec_variable

XML Editor

<batch:remove-record-variable doc:name="Record Variable" variableName="age" />

Accessing a Record Variable

To access a record variable within the Process and On Complete phases of batch processing, use the following expression:

#[recordVars['foo']]

For example, say you conditionally set a record variable on records in the first batch step – maybe wherever the value of state is Maine, you set a recordVars for "qualified".

<batch:set-record-variable-transformer doc:name="Record Variable" variableName="qualified" value="#[message.payload.state['ME']]"/>

In the second batch step, you can use an accept expression to instruct the step to process only qualified records, as shown below.

#[recordVars['qualified']]

See Also