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
Newsletter
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

  • How You Clear Your HTML5 Canvas Matters
  • Part 3: End-to-End Tracing and Observability Across Goose, agentgateway, and Quarkus
  • PWA on iOS, Part 1: PWAs on the iPhone Are Older Than They Look
  • AI Agents and Frontier Models: Insights From The Neuron

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

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
·
Sep. 06, 18 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
32.3K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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