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
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • How To Use AzureSignTool to Sign Executables With Azure DevOps
  • Building a Flask Web Application With Docker: A Step-by-Step Guide
  • How To Build a Google Photos Clone - Part 1
  • Implementing ROS Communication Patterns

Trending

  • Prompt Injection Is Real, So I Built a Python Firewall for LLM Pipelines
  • Observability for Agents and Workflows: Tracing Prompts, Tool Calls, and Business Outcomes End-to-End
  • Combining Temporal and Kafka for Resilient Distributed Systems
  • Agentic AI Has an Observability Blind Spot Nobody Is Talking About

Mule 4: Creating Global Custom Functions in Dataweave 2.0

In this article, I will explain how to create a global function that can be access or reuse by other Transform Message Component within a Mule Application.

By 
Enrico Rafols Dela Cruz user avatar
Enrico Rafols Dela Cruz
·
Sep. 06, 18 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
32.1K Views

Join the DZone community and get the full member experience.

Join For Free

In this article, I will explain how to create a global function that can be access or reuse by other Transform Message Component within a Mule Application.

First, We need to create a Dataweave File (.dwl) and save it in src/main/resources/modules/. Now,we can define our global custom functions here by using the fun directive and global variable by using var directive. Also note thatthis dwl file should not contain an output directory, body expression, or the separator (---) between header and body sections.

Image title

After creating a Global Dataweave Module, we can now reuse and import it into another Dataweave Script, any functions, variables, types, and namespaces defined in that custom module become available for use in the Dataweave Body.

Image title

We can use the import directive to import the custom module modules::MyGlobalCustomFunctions, which is stored in src/main/resources/modules/MyGlobalCustomFunctions.dwl into another Dataweave Script. On the above code, I used alies (as) to reference the instance of the imported custom module to a call alies, in this case, I can simply invoke the global function using call::formatDate instead of MyGlobalCustomFunctions::formatDate.

That's it, For more details about this new functionality of Dataweave 2.0, Check this oout: https://docs.mulesoft.com/mule4-user-guide/v/4.1/dataweave-create-module

Directive (programming) application Directory

Opinions expressed by DZone contributors are their own.

Related

  • How To Use AzureSignTool to Sign Executables With Azure DevOps
  • Building a Flask Web Application With Docker: A Step-by-Step Guide
  • How To Build a Google Photos Clone - Part 1
  • Implementing ROS Communication Patterns

Partner Resources

×

Comments

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

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

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 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook