Contact Us 1-800-596-4880

Remove Variable (<remove-variable/>)

Removes a Mule variable from a Mule event.

Component XML

This component supports the following XML structure:

<remove-variable
  doc:name="Remove Variable"
  variableName="myMuleVar" />

Remove Variable (<remove-variable/>) attributes are configurable through the UI and XML.

Attribute Name Attribute XML Description

Remove variable (default)

doc:name

Editable name for the component to display in the canvas.

N/A

doc:id

Automatically generated identifier for the component.

Variable name

variableName

Name of the Mule variable to remove.

Examples

The following example shows how to remove a Mule variable from the flow:

<flow name="remove-variable-ex" >
  <scheduler doc:name="Scheduler" > (1)
    <scheduling-strategy >
      <fixed-frequency frequency="10" timeUnit="SECONDS"/>
    </scheduling-strategy>
  </scheduler>
  <set-variable value='"value of my Mule variable"' doc:name="Set Variable"
                variableName="myMuleVar"/> (2)
  <logger level="INFO" doc:name="Logger"
          message="#[vars.myMuleVar]"
          category="PRINT VALUE OF VARIABLE"/> (3)
  <remove-variable doc:name="Remove Variable"
                   variableName="myMuleVar"/> (4)
  <logger level="INFO" doc:name="Logger"
           category="ATTEMPT TO PRINT VALUE OF REMOVED VARIABLE"
           message="#[vars.myMuleVar]"/> (5)
  <remove-variable doc:name="Remove Variable"
                   variableName="banana"/> (6)
</flow>
1 The Scheduler component triggers the flow.
2 Set Variable creates a Mule variable (myMuleVar).
3 The first Logger in the flow prints the value of the variable ("value of my Mule variable").
4 Remove Variable provides a string with the name of the variable (variableName="myMuleVar") to remove the variable from the Mule event.
5 The second Logger prints null because the Mule variable no longer exists.
6 The second Remove Variable logs a WARN message because it attempts to remove a Mule variable (banana) that does not exist in the Mule event.

The following example shows the logs for an execution of this flow:

INFO  2022-12-15 08:33:20,151 ...event: 2f65e920-7c96-11ed-97ec-147ddaaf4f97]
PRINT VALUE OF VARIABLE: "value of my Mule variable"

INFO  2022-12-15 08:33:20,155 ...event: 2f65e920-7c96-11ed-97ec-147ddaaf4f97]
ATTEMPT TO PRINT VALUE OF REMOVED VARIABLE: null

WARN  2022-12-15 08:33:20,156 ...event: 2f65e920-7c96-11ed-97ec-147ddaaf4f97]
...RemoveFlowVariableProcessor: There is no variable named 'banana'.
Check the 'variableName' parameter in the 'remove-variable' component at
remove-variable-ex/processors/4