Contact Us 1-800-596-4880

Variables in Mule Apps

This version of Mule reached its End of Life on May 2, 2023, when Extended Support ended.

Deployments of new applications to CloudHub that use this version of Mule are no longer allowed. Only in-place updates to applications are permitted.

MuleSoft recommends that you upgrade to the latest version of Mule 4 that is in Standard Support so that your applications run with the latest fixes and security enhancements.

Variables are used to store per-event values for use within a flow of a Mule app. The stored data can be any supported data type, such as an object, number, or string. It is also possible to store the current message (using the message keyword), the current message payload (using the payload keyword) or just the current message attributes (using the attributes keyword). You can even use a DataWeave expression as the value. However, the keyword vars (for example, vars.someOtherVar) is not allowed.

You can create, or update, variables in these ways:

  • Using the Set Variable component.

  • Using a Target Variable from within an operation, such as the Read operation to the File connector or the Store operation to the Database connector.

  • Using the DataWeave Transform Component (EE-Only)

  • Using Scripting Component (in scripting module)

You can also delete/remove:

  • Using the Remove Variable component.

After creating a variable, you can access and use it within the scope of a Mule flow where you created it, which includes any flows that are joined with it through a Flow Ref component.

  • vars: Keyword for accessing a variable, for example, through a DataWeave expression in a Mule component, such as the Logger, or from an Input or Output parameter of an operation. If the name of your variable is myVar, you can access it like this: vars.myVar

Note that a variable in the Mule event is different from variables defined in a DataWeave script, which are local to the script and not accessible outside of it.