Store the Entire Output of a Card in a Variable(Flow Designer)
You can store a value that is based on output of a card — that is, the entire output, part of the output, or a manipulation of the output — and then pass that variable to the next card, together with the output from the previous card.
Normally, a card outputs data that is different from the data that it received as input, as depicted by the first flow in the diagram.
The first flow carries out these steps:
-
Card A produces an output.
-
Card B receives the entire output from Card A.
However, when you create a target variable, the flow changes, as depicted in the second flow in the diagram, which carries out these steps:
-
Card A produces an output.
-
Card B receives the entire output from Card A. It stores its own output in a variable, and then passes the variable and the output from Card A to Card C.
-
Card C receives the output from Card A and the variable that contains the output of Card B.
When you want to a variable, it will appear in cards later in the flow. To use the flow from the tutorial "Create Your First Mule Application with Flow Designer" as an example, the variable OppDetails
is created early in the flow. The variable is still available in the Twilio card, which is the last card in the flow.
OppDetails
variable highlightedTo use the variable in this Twilio card (or in any card where a variable is available, other than the Transform card), you would simply drag it into a field.
Although |
Procedure
-
Open the card for which you want to direct the output into a variable.
-
Click Advanced on the left side of the card. Not all cards place the fields for creating target variables on the Advanced page. Also, not all cards can direct their output into target variables.
-
Specify a name for the variable in the Target field. Names can include only numbers, characters, and underscores.
-
Specify a DataWeave expression by clicking in the Target Value field to open the Custom Expression dialog, where you can compose an expression with the help of the Add data and Add functions panes on the right.
Figure 3. The Custom Expression window and its panesFor the Add data pane to appear, at least one of the previous cards must output a data type that is other than
Default
.For documentation about the DataWeave functions that are listed in the Add functions pane, see "Core" in the DataWeave Function Reference.
Example based on the screenshot of the Custom Expression window: If you wanted to save the payload’s error message into a variable, you would click
error_message
. The Expression field would then contain the expressionerror_message
. You would then click OK.Or you could also choose to type in a value. For example, if you wanted to store the entire payload in a variable, you could type
payload
in the Custom Expression field. -
Click OK in the Custom Expression dialog and then click the canvas to close the card.
Examples
To store the payload from the previous card, set the value of the variable to payload
.
To store the attributes from the previous card, set the value of the variable to attributes
.
To store the entire set of data at the current point in a flow, set the value of the variable to message
.
To store a Boolean value, set the value of the variable to true
or false
.