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.

Figure 1. An ordinary flow contrasted with a flow in which a card outputs to a target variable

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.

Figure 2. The Twilio card, with the OppDetails variable highlighted

To 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 OppDetails was created with a Set Variable card, it can be accessed and used in the same way as variables that are created though the use of the Target and Target Value fields in a card.

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 panes

For 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 expression error_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.

Sign up for our newsletter

MuleSoft provides a widely used integration platform for connecting SaaS and enterprise applications in the cloud and on-premises. Delivered as a unified integration experience, CloudHub™ and Mule ESB™ (enterprise service bus) are built on proven open source technology for fast and reliable on-premises and cloud integration without vendor lock-in. Our solutions also include Tcat, an Apache Tomcat server for enterprises.

We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.