DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Enterprise RIA With Spring 3, Flex 4 and GraniteDS
  • MuleSoft Integration With RabbitMQ
  • How to Use IBM App Connect's ‘Mapping Assist’ to Automatically Map Your Integration Flows
  • Implementing Real-Time Datadog Monitoring in Deployments

Trending

  • Transforming AI-Driven Data Analytics with DeepSeek: A New Era of Intelligent Insights
  • Evolution of Cloud Services for MCP/A2A Protocols in AI Agents
  • It’s Not About Control — It’s About Collaboration Between Architecture and Security
  • Issue and Present Verifiable Credentials With Spring Boot and Android
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. DataWeave Dynamic Evaluate Component Explained

DataWeave Dynamic Evaluate Component Explained

By using Dynamic Evaluate Component, this integration can be achieved by writing one flow and the transformation can be applied dynamically.

By 
Gary Liu user avatar
Gary Liu
DZone Core CORE ·
Sep. 09, 20 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
8.7K Views

Join the DZone community and get the full member experience.

Join For Free

Introduction

In Dataweave 2.0, we can execute the transformation of data (payload, attributes, variables, etc) dynamically. This component is called "Dynamic Evaluate Component" which is available since Mule 4.1. This component is extremely useful when we have the integration like the following:

execute report consumer

As shown above, the Execute Report Consumer is a Workday Custom Web Service, the operation is the same but the requests and responses are different. There could be up to 30 this kind of integrations. Without using Dynamic Evaluate Component, we have to write 30 similar flows. But by using Dynamic Evaluate Component, this integration can be achieved by writing one flow and the transformation can be applied dynamically.

Now the question is how can we achieve this?

Dynamic Evaluate Component

The gist of the dynamic evaluation is two steps as shown in the following diagram.

  • Step One: load the script
  • Step Two: Execute script

DWL script

Load Dataweave Scripts

XML
 




xxxxxxxxxx
1


 
1
%dw 2.0
2
output application/java
3
var dwlFilePath = 'classpath://dwl/' ++ (vars.myApp  default " ") ++ '.dwl'
4
---
5
readUrl(dwlFilePath, 'text/plain')



As shown above, the first step is to load the script to a variable, say, dwlScript. The xml form of the code is the following:

XML
 




xxxxxxxxxx
1
11


 
1
        <ee:transform doc:name="Read DWL Script" doc:id="3f00b2d7-3c64-48ed-ab89-9e67a278fe36" >
2
            <ee:message >
3
            </ee:message>
4
            <ee:variables >
5
                <ee:set-variable variableName="dwlScript" ><![CDATA[%dw 2.0
6
output application/java
7
var dwlFilePath = 'classpath://dwl/' ++ (vars.myApp  default " ") ++ '.dwl'
8
---
9
readUrl(dwlFilePath, 'text/plain')]]></ee:set-variable>
10
            </ee:variables>
11
        </ee:transform>



Note line 7, we predefine the application name. And the DataWeave script file name is dwl/${appName}.dwl.

Evaluate DataWeave Scripts

The Dynamic Evaluate Component takes the following form:

dataweave script

Note: the Parameters section contains objects as you do in var definition. As shown by the script. email and myDataType are refereed exactly like var.

JavaScript
 




xxxxxxxxxx
1


 
1
%dw 2.0
2
output application/json
3
---
4
{
5
    name: 'john doe',
6
    ssn: '123-45-3567',
7
    email: email,
8
    dataType: myDataType
9
}



Project Layout

The following is the same project layout. 

customer JSON

The source code can be found at GitHub: dynamic-evaluate-component

Here is the line of thinking:

  1. API Client pass application name
  2. Based on application name, we build dwl file path. The mapping is stored in yaml file myApp.to-json --> customer-to-json --> dwl/custom-to-json.dwl

Best Practices

  1. The naming convention of the dwl file must be clear and precise
  2. The dwl script file should contain application name dwl/${domain}-${application}.dwl, where domain could be Workday, Salesforce, etc if it is Workday or Salesforce integration.
  3. The dynamic scripts of transformation code must well be documented, otherwise, it could make later maintenance and bug fixing very challenging.
application Integration Flow (web browser) Form (document) XML Web Service Data (computing) GitHub

Opinions expressed by DZone contributors are their own.

Related

  • Enterprise RIA With Spring 3, Flex 4 and GraniteDS
  • MuleSoft Integration With RabbitMQ
  • How to Use IBM App Connect's ‘Mapping Assist’ to Automatically Map Your Integration Flows
  • Implementing Real-Time Datadog Monitoring in Deployments

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!