SlideShare a Scribd company logo
1 of 17
DataWeave in
MULE
By Nagarjunareddy
Using the DataWeave Transformer
 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.
 This generates a .dwl transformation file (or several of
them) that stores your code and is packaged with your
Mule application.
 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.
Setting Reader Parameters
 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.
Transform Section
 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.
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.
Re-scaffolding 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.
Referencing Existing Transforms
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.
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>
Output Section
 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.
Using DataWeave Language
Elsewhere
 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.
 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

Data weave component
Data weave componentData weave component
Data weave componentSindhu VL
 
Generic steps in informatica
Generic steps in informaticaGeneric steps in informatica
Generic steps in informaticaBhuvana Priya
 
OBIEE publisher with Report creation - Tutorial
OBIEE publisher with Report creation - TutorialOBIEE publisher with Report creation - Tutorial
OBIEE publisher with Report creation - Tutorialonlinetrainingplacements
 
Programming Without Coding Technology (PWCT) Environment
Programming Without Coding Technology (PWCT) EnvironmentProgramming Without Coding Technology (PWCT) Environment
Programming Without Coding Technology (PWCT) EnvironmentMahmoud Samir Fayed
 
Oracle Certification 1Z0-1041 Questions and Answers
Oracle Certification 1Z0-1041 Questions and AnswersOracle Certification 1Z0-1041 Questions and Answers
Oracle Certification 1Z0-1041 Questions and Answersdouglascarnicelli
 
Internet Environment
Internet  EnvironmentInternet  Environment
Internet Environmentguest8fdbdd
 
Rational Publishing Engine with Rational DOORS
Rational Publishing Engine with Rational DOORSRational Publishing Engine with Rational DOORS
Rational Publishing Engine with Rational DOORSGEBS Reporting
 
Oracle Form material
Oracle Form materialOracle Form material
Oracle Form materialRajesh Ch
 
5\9 SSIS 2008R2_Training - DataFlow Basics
5\9 SSIS 2008R2_Training - DataFlow Basics5\9 SSIS 2008R2_Training - DataFlow Basics
5\9 SSIS 2008R2_Training - DataFlow BasicsPramod Singla
 
Stop hardcoding follow parameterization
Stop hardcoding  follow parameterizationStop hardcoding  follow parameterization
Stop hardcoding follow parameterizationPreeti Sagar
 

What's hot (14)

Data weave component
Data weave componentData weave component
Data weave component
 
Generic steps in informatica
Generic steps in informaticaGeneric steps in informatica
Generic steps in informatica
 
OBIEE publisher with Report creation - Tutorial
OBIEE publisher with Report creation - TutorialOBIEE publisher with Report creation - Tutorial
OBIEE publisher with Report creation - Tutorial
 
Programming Without Coding Technology (PWCT) Environment
Programming Without Coding Technology (PWCT) EnvironmentProgramming Without Coding Technology (PWCT) Environment
Programming Without Coding Technology (PWCT) Environment
 
Oracle Certification 1Z0-1041 Questions and Answers
Oracle Certification 1Z0-1041 Questions and AnswersOracle Certification 1Z0-1041 Questions and Answers
Oracle Certification 1Z0-1041 Questions and Answers
 
Internet Environment
Internet  EnvironmentInternet  Environment
Internet Environment
 
Rational Publishing Engine with Rational DOORS
Rational Publishing Engine with Rational DOORSRational Publishing Engine with Rational DOORS
Rational Publishing Engine with Rational DOORS
 
Oracle Form material
Oracle Form materialOracle Form material
Oracle Form material
 
5\9 SSIS 2008R2_Training - DataFlow Basics
5\9 SSIS 2008R2_Training - DataFlow Basics5\9 SSIS 2008R2_Training - DataFlow Basics
5\9 SSIS 2008R2_Training - DataFlow Basics
 
VB6 Using ADO Data Control
VB6 Using ADO Data ControlVB6 Using ADO Data Control
VB6 Using ADO Data Control
 
Sq lite module8
Sq lite module8Sq lite module8
Sq lite module8
 
Reports 6i
Reports 6iReports 6i
Reports 6i
 
Stop hardcoding follow parameterization
Stop hardcoding  follow parameterizationStop hardcoding  follow parameterization
Stop hardcoding follow parameterization
 
Db2 tutorial
Db2 tutorialDb2 tutorial
Db2 tutorial
 

Similar to DataWeave in MULE - Transform Messages Using DataWeave Language

Similar to DataWeave in MULE - Transform Messages Using DataWeave Language (20)

Dataweave 160103180124
Dataweave 160103180124Dataweave 160103180124
Dataweave 160103180124
 
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
 
Mule data weave
Mule data weaveMule data weave
Mule data weave
 
Data weave in Mule
Data weave in MuleData weave in Mule
Data weave in Mule
 
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 in studio
Dataweave in studioDataweave in studio
Dataweave in studio
 
Mca 504 dotnet_unit5
Mca 504 dotnet_unit5Mca 504 dotnet_unit5
Mca 504 dotnet_unit5
 
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
 
Mule with data weave
Mule with data weaveMule with data weave
Mule with data weave
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
 
Template builder for word tutorial
Template builder for word tutorialTemplate builder for word tutorial
Template builder for word tutorial
 

More from Nagarjuna reddy

Transformation from csv to xml
Transformation  from csv to xmlTransformation  from csv to xml
Transformation from csv to xmlNagarjuna reddy
 
Translation from csv to xml
Translation from csv to xmlTranslation from csv to xml
Translation from csv to xmlNagarjuna reddy
 
Webapplicationwithmule by nagarjuanreddy
Webapplicationwithmule by nagarjuanreddyWebapplicationwithmule by nagarjuanreddy
Webapplicationwithmule by nagarjuanreddyNagarjuna reddy
 
Muleexpressiontransformer by nagarjuanreddy
Muleexpressiontransformer by nagarjuanreddyMuleexpressiontransformer by nagarjuanreddy
Muleexpressiontransformer by nagarjuanreddyNagarjuna reddy
 
Iot and mulesoft nagarjuna reddy
Iot and mulesoft nagarjuna reddyIot and mulesoft nagarjuna reddy
Iot and mulesoft nagarjuna reddyNagarjuna reddy
 
Introductiontocloudhubwithmulesoft by nagarjunareddy
Introductiontocloudhubwithmulesoft by nagarjunareddyIntroductiontocloudhubwithmulesoft by nagarjunareddy
Introductiontocloudhubwithmulesoft by nagarjunareddyNagarjuna reddy
 

More from Nagarjuna reddy (6)

Transformation from csv to xml
Transformation  from csv to xmlTransformation  from csv to xml
Transformation from csv to xml
 
Translation from csv to xml
Translation from csv to xmlTranslation from csv to xml
Translation from csv to xml
 
Webapplicationwithmule by nagarjuanreddy
Webapplicationwithmule by nagarjuanreddyWebapplicationwithmule by nagarjuanreddy
Webapplicationwithmule by nagarjuanreddy
 
Muleexpressiontransformer by nagarjuanreddy
Muleexpressiontransformer by nagarjuanreddyMuleexpressiontransformer by nagarjuanreddy
Muleexpressiontransformer by nagarjuanreddy
 
Iot and mulesoft nagarjuna reddy
Iot and mulesoft nagarjuna reddyIot and mulesoft nagarjuna reddy
Iot and mulesoft nagarjuna reddy
 
Introductiontocloudhubwithmulesoft by nagarjunareddy
Introductiontocloudhubwithmulesoft by nagarjunareddyIntroductiontocloudhubwithmulesoft by nagarjunareddy
Introductiontocloudhubwithmulesoft by nagarjunareddy
 

Recently uploaded

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxnada99848
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 

Recently uploaded (20)

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptx
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 

DataWeave in MULE - Transform Messages Using DataWeave Language

  • 2. Using the DataWeave Transformer  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.  This generates a .dwl transformation file (or several of them) that stores your code and is packaged with your Mule application.
  • 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. Setting Reader Parameters  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.
  • 8. Transform Section  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.
  • 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. Re-scaffolding 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.
  • 11. Referencing Existing Transforms 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.
  • 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. Output Section  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.
  • 16. Using DataWeave Language Elsewhere  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.
  • 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})`]