Mulesoft — Global Function in Dataweave 2.0

Gopal Ji Singh
Mar 21, 2022

This article is to create a global function that can be accessed or reused by other Transform Message Component within a Mule Application.


  1. Reusable
  2. Cleaner code
  3. Easy Maintenance
  4. Modularity

How to implement: Function 1: check minimum and the maximum length of a string Function 2: Remove preceding zeros from a string

Step 1: Create a data weave file in src/main/resources/modules/

Custome Function location

Step 2: Define global custom functions by using the fun directive Sample Dataweave code for functions.dwl:

DWL, Dataweave, global function

Note: The dwl file should not contain an output directory, body expression, or the separator ( — -) between header and body sections.

Step 3: Import directive to import the custom module modules::functions, which is stored in src/main/resources/modules/functions.dwl into another Dataweave Script

simply invoke the global function using func::<function name>

Sample Code:

Cheers :)