SlideShare a Scribd company logo
1 of 17
DataWeave
By Aditya Kuchan
 In Anypoint Studio, you can place a Transform
Message element in a flow to create transformations using
the DataWeave language. The editor helps you do this by
offering intelligent autocomplete suggestions, an output
preview that is updated in real time as you make changes,
and by building an initial scaffolding for your code, based
on the available metadata in your flow. This generates
a .dwl transformation file (or several of them) that stores
your code and is packaged with your Mule application.
Using the DataWeave Transformer
 When adding a Transform Message element to a Mule Flow,
it takes the elements from the incoming Mule Message as
its inputs. It then performs the necessary actions to produce
a Mule message as output for the next element in the flow
 The DataWeave Text Editor GUI
 The Transform Message element allows you to freely
write DataWeave code.
 If you click on an instance of the Transform Message
element in your flow, its properties editor will be displayed.
This editor is divided into three sections:
 Input
 Transform
 Output
Input Section
In the main tab, a tree view shows the known metadata
contents of the incoming Mule Message, allowing you to
explore it and know what data is available for using as an
input, and how to reference each part of it.
If the Mule flow doesn’t expose Metadata about the elements
you need from the incoming message, you can manually
specify it. To do so, select the element of the input you desire
to define, note that the pencil icon at the top right is no
longer grayed out. Click this icon to open a new tab in your
input section where you can define a sample with the
structure of this data.
When the input is of JSON or XML types, the sample input contains plain XML or JSON
code. When the input is of type POJO or DataWeave, the sample input is written
in DataWeave for more simplicity. In these cases the sample DataWeave code is merely a
way to display the sample data, not a transformation in itself.
 Some input formats, like CSV, allow you to define a
reader with specific properties that make
DataWeave parse inputs differently. Select the
input element you wish to configure on the tree
view of the input section, then click the gear icon.
Setting Reader Parameters
 you write the actual DataWeave code that carries out
the transform. Notice that changing the type of your
output directive changes the output section of the
editor. Although DataWeave as a language supports
adding input directives and naming these by any
name you like, in Studio the elements of the input
message are implicitly considered input directives and
so they don’t need to be defined in the header.
Transform Section
If Studio has any metadata about the components that are
upstream or downstream from your Transform Message
element at the time when you add the component to your
flow, a scaffolding for your DataWeave code is written out
automatically, with as much depth as Studio can intelligently
deduce. In some cases, this code may be enough to carry out
the transformation you need, and no additional coding is
needed. Sometimes, all you need to do is fill in the blank
spaces in the scaffolding with references to the input fields,
other times you may want to carry out more complex
operations that involve aggregation, filtering, calculations,
defining custom functions, etc and there you must write this
out in DataWeave code.
 Once you’ve added the Transform Message element to your
flow, any further changes you make to the surrounding
message processors and their metadata won’t affect
your `.dw`l file. You may still click the Scaffolding button on
the top left of the DataWeave properties editor any time
you want and have a new scaffolding built, note that this
will erase anything you’ve written in the DataWeave
body. Doing this won’t affect any directives you defined in
your header (except for the output directive). Use this
button if you’ve made any changes to elements that come
after the Transform Message element on the flow that
expose metadata and don’t mind loosing what you’ve
already written into the transform’s body.
Re-scaffolding
Instead of defining a new .dwl file, you can reference an
existing one by clicking theData Source button, selecting On
File as the source and referencing the correct file.
Referencing Existing Transforms
Handling Multiple Outputs
A single Transform Message element can give shape to several
different components of the output Mule message. Each of
these output components must be defined in a
separate .dwl file, written out in a separate tab of the
Transform section. For example in one tab you may be
defining the payload contents, in another those of an
outbound property, and these will both be parts of the same
output Mule message
To add a new output, click the Plus sign at the
bottom right of the section:new+output.png[image]
A new tab will then appear, there you can specify
where in the output Mule message to place the
output of this DataWeave transform. In case you’re
creating a new variable or property, you must also set
a name for it.
In the XML editor you can do the same by adding multiple child
elements inside thedw:transform-message component.
<dw:transform-message>
<dw:set-payload resource="classpath:path/transform.dwl"/> <dw:set-
variable variableName="myVariable"
resource="classpath:path/transform.dwl"/> <dw:set-session-variable
variableName="mySessionVariable"
resource="classpath:path/transform.dwl"/> </dw:transform-message>
 This section has two tabs, one of them shows you a neat
expandable tree view of the output data structure, the
other shows you a preview of what the actual output looks
like, built from any sample data you provide in the input
section. As you make changes in the transport section,
notice how the data structure changes. The output of the
transformer is made into the selected component of the
output mule message. If your transformer has multiple
outputs, the Preview tab will display the one
corresponding to the currently selected transform.
Output Section
 All components in Mule that support Mule Expression
Language also support expressions written in DataWeave
Language. To invoke an expression written in DataWeave
language, simply invoke the dw() function, the expression
will return whatever the transform outputs.
 DataWeave expressions defined within this function work
just as those defined within a Transform Message element,
the only difference is that the output is returned into the
expression’s result, wherever it may be.
Using DataWeave Language
Elsewhere
 For example, you can define a custom object and populate it
with elements from the payload:
 That same expression could be added inside a Logger,
 within a MEL expression, to print out its result:
dw(myobject:{id:payload.accountid, user:payload.user})
#[`dw(myobject:{id:payload.accountid, user:payload.user})`]

More Related Content

What's hot

Mule Collection Aggregator
Mule Collection AggregatorMule Collection Aggregator
Mule Collection AggregatorAnkush Sharma
 
Mule Microsoft Dynamics AX 2012 Connector
Mule Microsoft Dynamics AX 2012 ConnectorMule Microsoft Dynamics AX 2012 Connector
Mule Microsoft Dynamics AX 2012 ConnectorAnkush Sharma
 
Junit in mule demo
Junit in mule demoJunit in mule demo
Junit in mule demoSudha Ch
 
Mule addcontactsintosalesforce
Mule addcontactsintosalesforceMule addcontactsintosalesforce
Mule addcontactsintosalesforcehimajareddys
 
Introduction to dataweave
Introduction to dataweaveIntroduction to dataweave
Introduction to dataweaveSwati Deshpande
 
Creating restful api using mule esb
Creating restful api using mule esbCreating restful api using mule esb
Creating restful api using mule esbRaviShankar Mishra
 
Mule tcat server - Monitoring a server
Mule tcat server - Monitoring a serverMule tcat server - Monitoring a server
Mule tcat server - Monitoring a serverShanky Gupta
 
Data weave reference documentation
Data weave reference documentationData weave reference documentation
Data weave reference documentationD.Rajesh Kumar
 
Content based routing tutorial in mule
Content based routing tutorial in muleContent based routing tutorial in mule
Content based routing tutorial in muleSindhu VL
 
Automatic documentation with mule
Automatic documentation with muleAutomatic documentation with mule
Automatic documentation with muleF K
 
Dataweavewithflowreflookup
DataweavewithflowreflookupDataweavewithflowreflookup
Dataweavewithflowreflookuphimajareddys
 
Mulesoft salesforce connector to update Object.
Mulesoft salesforce connector to update Object.Mulesoft salesforce connector to update Object.
Mulesoft salesforce connector to update Object.Yogesh Chandr
 
Mule using Salesforce
Mule using SalesforceMule using Salesforce
Mule using SalesforceKhasim Cise
 
File component in mule
File component in muleFile component in mule
File component in muleRajkattamuri
 
Mule edifact module
Mule edifact moduleMule edifact module
Mule edifact moduleSon Nguyen
 

What's hot (18)

Mule Collection Aggregator
Mule Collection AggregatorMule Collection Aggregator
Mule Collection Aggregator
 
Mule Microsoft Dynamics AX 2012 Connector
Mule Microsoft Dynamics AX 2012 ConnectorMule Microsoft Dynamics AX 2012 Connector
Mule Microsoft Dynamics AX 2012 Connector
 
Processing files sequentially in mule
Processing files sequentially in muleProcessing files sequentially in mule
Processing files sequentially in mule
 
Muleesb
MuleesbMuleesb
Muleesb
 
Junit in mule demo
Junit in mule demoJunit in mule demo
Junit in mule demo
 
Mule addcontactsintosalesforce
Mule addcontactsintosalesforceMule addcontactsintosalesforce
Mule addcontactsintosalesforce
 
Mule velocity
Mule velocityMule velocity
Mule velocity
 
Introduction to dataweave
Introduction to dataweaveIntroduction to dataweave
Introduction to dataweave
 
Creating restful api using mule esb
Creating restful api using mule esbCreating restful api using mule esb
Creating restful api using mule esb
 
Mule tcat server - Monitoring a server
Mule tcat server - Monitoring a serverMule tcat server - Monitoring a server
Mule tcat server - Monitoring a server
 
Data weave reference documentation
Data weave reference documentationData weave reference documentation
Data weave reference documentation
 
Content based routing tutorial in mule
Content based routing tutorial in muleContent based routing tutorial in mule
Content based routing tutorial in mule
 
Automatic documentation with mule
Automatic documentation with muleAutomatic documentation with mule
Automatic documentation with mule
 
Dataweavewithflowreflookup
DataweavewithflowreflookupDataweavewithflowreflookup
Dataweavewithflowreflookup
 
Mulesoft salesforce connector to update Object.
Mulesoft salesforce connector to update Object.Mulesoft salesforce connector to update Object.
Mulesoft salesforce connector to update Object.
 
Mule using Salesforce
Mule using SalesforceMule using Salesforce
Mule using Salesforce
 
File component in mule
File component in muleFile component in mule
File component in mule
 
Mule edifact module
Mule edifact moduleMule edifact module
Mule edifact module
 

Similar to Data weave

Similar to Data weave (20)

Dataweave by nagarjuna
Dataweave  by nagarjunaDataweave  by nagarjuna
Dataweave by nagarjuna
 
Data weave
Data weaveData weave
Data weave
 
Data weave
Data weave Data weave
Data weave
 
Data weave
Data weave Data weave
Data weave
 
Data weave
Data weave Data weave
Data weave
 
Data weave
Data weave Data weave
Data weave
 
Data weave
Data weaveData weave
Data weave
 
Data weave
Data weave Data weave
Data weave
 
Data weave
Data weave Data weave
Data weave
 
Data weave
Data weave Data weave
Data weave
 
Data weave
Data weave Data weave
Data weave
 
Dataweave nagarjuna
Dataweave nagarjunaDataweave nagarjuna
Dataweave nagarjuna
 
Dataweave Basic
Dataweave BasicDataweave Basic
Dataweave Basic
 
Mca 504 dotnet_unit5
Mca 504 dotnet_unit5Mca 504 dotnet_unit5
Mca 504 dotnet_unit5
 
OBIEE publisher with Report creation - Tutorial
OBIEE publisher with Report creation - TutorialOBIEE publisher with Report creation - Tutorial
OBIEE publisher with Report creation - Tutorial
 
Data weave documentation
Data weave documentationData weave documentation
Data weave documentation
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
 
Muledataweave10 161029032456-161119152200
Muledataweave10 161029032456-161119152200Muledataweave10 161029032456-161119152200
Muledataweave10 161029032456-161119152200
 
Mule dataweave
Mule dataweaveMule dataweave
Mule dataweave
 
Data weave in mule
Data weave in muleData weave in mule
Data weave in mule
 

Recently uploaded

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 

Recently uploaded (20)

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 

Data weave

  • 2.  In Anypoint Studio, you can place a Transform Message element in a flow to create transformations using the DataWeave language. The editor helps you do this by offering intelligent autocomplete suggestions, an output preview that is updated in real time as you make changes, and by building an initial scaffolding for your code, based on the available metadata in your flow. This generates a .dwl transformation file (or several of them) that stores your code and is packaged with your Mule application. Using the DataWeave Transformer
  • 3.  When adding a Transform Message element to a Mule Flow, it takes the elements from the incoming Mule Message as its inputs. It then performs the necessary actions to produce a Mule message as output for the next element in the flow
  • 4.  The DataWeave Text Editor GUI  The Transform Message element allows you to freely write DataWeave code.  If you click on an instance of the Transform Message element in your flow, its properties editor will be displayed. This editor is divided into three sections:  Input  Transform  Output
  • 5. Input Section In the main tab, a tree view shows the known metadata contents of the incoming Mule Message, allowing you to explore it and know what data is available for using as an input, and how to reference each part of it. If the Mule flow doesn’t expose Metadata about the elements you need from the incoming message, you can manually specify it. To do so, select the element of the input you desire to define, note that the pencil icon at the top right is no longer grayed out. Click this icon to open a new tab in your input section where you can define a sample with the structure of this data.
  • 6. When the input is of JSON or XML types, the sample input contains plain XML or JSON code. When the input is of type POJO or DataWeave, the sample input is written in DataWeave for more simplicity. In these cases the sample DataWeave code is merely a way to display the sample data, not a transformation in itself.
  • 7.  Some input formats, like CSV, allow you to define a reader with specific properties that make DataWeave parse inputs differently. Select the input element you wish to configure on the tree view of the input section, then click the gear icon. Setting Reader Parameters
  • 8.  you write the actual DataWeave code that carries out the transform. Notice that changing the type of your output directive changes the output section of the editor. Although DataWeave as a language supports adding input directives and naming these by any name you like, in Studio the elements of the input message are implicitly considered input directives and so they don’t need to be defined in the header. Transform Section
  • 9. If Studio has any metadata about the components that are upstream or downstream from your Transform Message element at the time when you add the component to your flow, a scaffolding for your DataWeave code is written out automatically, with as much depth as Studio can intelligently deduce. In some cases, this code may be enough to carry out the transformation you need, and no additional coding is needed. Sometimes, all you need to do is fill in the blank spaces in the scaffolding with references to the input fields, other times you may want to carry out more complex operations that involve aggregation, filtering, calculations, defining custom functions, etc and there you must write this out in DataWeave code.
  • 10.  Once you’ve added the Transform Message element to your flow, any further changes you make to the surrounding message processors and their metadata won’t affect your `.dw`l file. You may still click the Scaffolding button on the top left of the DataWeave properties editor any time you want and have a new scaffolding built, note that this will erase anything you’ve written in the DataWeave body. Doing this won’t affect any directives you defined in your header (except for the output directive). Use this button if you’ve made any changes to elements that come after the Transform Message element on the flow that expose metadata and don’t mind loosing what you’ve already written into the transform’s body. Re-scaffolding
  • 11. Instead of defining a new .dwl file, you can reference an existing one by clicking theData Source button, selecting On File as the source and referencing the correct file. Referencing Existing Transforms
  • 12. Handling Multiple Outputs A single Transform Message element can give shape to several different components of the output Mule message. Each of these output components must be defined in a separate .dwl file, written out in a separate tab of the Transform section. For example in one tab you may be defining the payload contents, in another those of an outbound property, and these will both be parts of the same output Mule message
  • 13. To add a new output, click the Plus sign at the bottom right of the section:new+output.png[image] A new tab will then appear, there you can specify where in the output Mule message to place the output of this DataWeave transform. In case you’re creating a new variable or property, you must also set a name for it.
  • 14. In the XML editor you can do the same by adding multiple child elements inside thedw:transform-message component. <dw:transform-message> <dw:set-payload resource="classpath:path/transform.dwl"/> <dw:set- variable variableName="myVariable" resource="classpath:path/transform.dwl"/> <dw:set-session-variable variableName="mySessionVariable" resource="classpath:path/transform.dwl"/> </dw:transform-message>
  • 15.  This section has two tabs, one of them shows you a neat expandable tree view of the output data structure, the other shows you a preview of what the actual output looks like, built from any sample data you provide in the input section. As you make changes in the transport section, notice how the data structure changes. The output of the transformer is made into the selected component of the output mule message. If your transformer has multiple outputs, the Preview tab will display the one corresponding to the currently selected transform. Output Section
  • 16.  All components in Mule that support Mule Expression Language also support expressions written in DataWeave Language. To invoke an expression written in DataWeave language, simply invoke the dw() function, the expression will return whatever the transform outputs.  DataWeave expressions defined within this function work just as those defined within a Transform Message element, the only difference is that the output is returned into the expression’s result, wherever it may be. Using DataWeave Language Elsewhere
  • 17.  For example, you can define a custom object and populate it with elements from the payload:  That same expression could be added inside a Logger,  within a MEL expression, to print out its result: dw(myobject:{id:payload.accountid, user:payload.user}) #[`dw(myobject:{id:payload.accountid, user:payload.user})`]