Nav

To Create and Populate a Variable (Design Center)

This first procedure in this topic creates a new variable and populates it with data that’s returned by the operation. For example, you can set the variable to the response from the HTTP Request. The variable value is a Mule message object that overwrites the payload, not the main Mule message. A Mule message object contains:

  • An attributes object that contains metadata about the nature of the data request.

  • A payload object that contains the actual data.

The second procedure in this topic creates a variable using Transform.

The scope of a variable is the Mule event. If you need variables to persist outside the event, use an object store. In this release, only one type of variable exists.

  1. Open any component that isn’t acting as a flow trigger. For example, open an HTTP Request component.

  2. In Advanced, in the Target Variable, enter a name for the variable.

    to create and populate a variable 3a582

You can access the saved payload downstream using the syntax:

vars.MyVariable.payload

Create a Variable Using Transform

  1. Add Transform to the flow, and hardcode a variable value to the name of the table you want to query:

    • In Transform, on the Mappings tab, select Output Payload > Add Transformation.

    • In Type, select Vars.

      transform vars

      Name: appears.

    • In Name, enter a variable name, for example cm_table.

    • Click Create.

    • In the center of the Mappings pane, click Set Data Type.

    • In Transform, in Data Type for Variables cm_table, select New Data Type.

    • In Name, type a name, for example tablename.

    • In Format, accept the default, JSON.

    • In Type, select From Example and replace the default example with the following string in quotation marks:

      "tablenamestring"

    • Click Apply Changes and then, click Keep Transformation if prompted.

    • To populate the variable, in Output Vars - cmtable, double-click Variables String:

    • Replace the null with the table name enclosed in quotation marks. For example, type "payments".

      Variables String

      Now, you can access the variable value, payments, from the Mule event in the next part of the flow using the expression vars.cm_table. For example, the following database connector Select operation selects all records from the payments table:

      'SELECT * FROM ' vars.cm_table

See also