Contact Us 1-800-596-4880

Add Another Output to the Transform Message Component (Anypoint Studio)

A single Transform Message component can give shape to several different parts of the output Mule event (the payload, variables, and attributes). Each different output part must be defined in a separate target XML element inside the <ee:transform> XML element as another block of DataWeave code. In Anypoint Studio 7, you do this by writing the DataWeave code in a separate tab of the Transform pane. For example, if one tab defines the payload, and another attributes, these are both parts of the same output Mule event.

To add a new output target:

  1. Click Add new target.

    using dataweave in studio 34a3e

  2. Specify where in the output Mule message to place the result of this new DataWeave transform. In case you’re creating a new variable or property, you must also set a name for it.

    new variable

Note that the execution order of multiple outputs can vary. Ensure that each transformation is independent of the order of execution and the other outputs.

How Targets of a Transform Message Component are Represented in the Configuration XML File

The payload is represented in an <ee:message> element, as a child element of the <ee:message> element.

<ee:transform doc:name="Set Transactions XML" doc:id="5c58d889-896d-495a-b2f6-fe1613ae8044" >
  <ee:message >
    <ee:set-payload ><![CDATA[%dw 2.0
                              output application/xml
                              ...]]>

Attributes are represented together inside the <ee:message> element, as a child of the <ee:message> element.

<ee:transform doc:name="Set Transactions XML">
  <ee:message >
    <ee:set-payload ><![CDATA[%dw 2.0
                              output application/xml
                              ...]]>
    </ee:set-payload/>

    <ee:set-attributes>
    <![CDATA[%dw 2.0
             output application/java
             ---
            { }]]>
    </ee:set-attributes>
  </ee:message>
  ...
</ee:transform>

Each variable is represented inside a separate <ee:variable> element, as a child the <ee:variables> parent element. The <ee:variables> element is a direct child of the <ee:transform> element, so it is not part of the <ee:message> element. This XML structure reflects that variables and the message are carried along together with the parent event object.

Here is an example of a variable target defined inside a Transform Message component:

<ee:transform doc:name="Set accounts var" doc:id="15e226ab-8204-4d84-ab4b-f4fcdd088656">
  <ee:message>
  ...
  </ee:message>
  <ee:variables>
    <ee:set-variable variableName="accounts">
      <![CDATA[%dw 2.0
               output application/json
               ---
               ...]]>
    </ee:variable>
  </ee:variables>
</ee:transform>