Record Variable

Mule Runtime Engine versions 3.5, 3.6, and 3.7 reached End of Life on or before January 25, 2020. For more information, contact your Customer Success Manager to determine how you can 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.



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 way 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.

    Studio Visual Editor


    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.


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.

Studio Visual Editor


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:


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.


See Also

Was this article helpful?

💙 Thanks for your feedback!

View on GitHub