Contact Free trial Login

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.

fd target variables
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:

  1. Card A produces an output.

  2. 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:

  1. Card A produces an output.

  2. 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.

  3. 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.

fd set var twilio
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

  1. Open the card for which you want to direct the output into a variable.

  2. 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.

  3. Specify a name for the variable in the Target field. Names can include only numbers, characters, and underscores.

  4. 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.

    fd set var custom expression dialog
    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.

  5. 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.

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.