Mule4 - Dynamic Evaluate Component

Mule4 - Dynamic Evaluate Component

This article explains about Dynamic Evaluate Component in Mule which helps in executing dynamic dataweave scripts.

Dynamic Evaluate

  • A behavior which allows you to dynamically select the dataweave script instead of hardcoding the script in the Transform Message component.
  • This component lets you execute an expression which eventually evaluates a Dataweave script where in the expression being executed here again results in a dataweave script.
  • This way we can dynamically select the dataweave script to be executed with respect to any varying parameter.

Functional Scenario: 

Assume we are in API led connectivity approach where we have 

  •  A set of Experience APIs invoked by different applications like salesforce, SAP, Mobile Apps, Web Apps etc for the same functionality.
  • A Process API to orchestrate the response coming from System API with respect to source of the request.
  • A System API which connects to backend systems like databases etc to get the required data.
No alt text provided for this image

All the client applications in our example may not require all the data retrieved from system API. So, in the process API orchestration if we had to respond to different client applications with different response structures, in general case we will end up designing each flow for each client app to achieve this.

But using a dynamic evaluate component without using choice router and without defining different flows respective to different client applications we can achieve this dynamic response.

Let us check the example in Anypoint studio

  • Create a mule project
  • Create dwl files as shown below specific to each Client Application
No alt text provided for this image
  • Set below payload in Transform Message Component and assume it to act as response from system API
No alt text provided for this image
  • Create a mule variable to store the dynamic dataweave client specific script using readUrl() in which dw file to be picked is based on the queryParam(appName) passed by client application
No alt text provided for this image
  • Configure Dynamic Evaluate Component to read the dynamic script and run on the payload.
No alt text provided for this image
  • Final Mule Flow
No alt text provided for this image
No alt text provided for this image

Video Tutorial:


Codebase :





Nice concept and good explanation.

To view or add a comment, sign in

More articles by Praneeth V.

  • Mule 4 - Mule Server Notifications

    Every API to be developed on any technology will have both Functional and Non Functional Requirements to it. Functional…

Explore content categories