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

  • Why 200 OK Is the Most Dangerous Lie in Enterprise Integration
  • Streaming vs In-Memory DataWeave: Designing for 1M+ Records Without Crashing
  • Optimizing MuleSoft Performance With HikariCP: A Complete Guide
  • Exploring Deployment Options in Mule 4

Trending

  • Microsoft Fabric Throttling: Diagnose Before You Scale
  • PWA on iOS, Part 1: PWAs on the iPhone Are Older Than They Look
  • Article Moderation: Your Questions, Answered
  • Frame Buffer Hashing for Visual Regression on Embedded Devices

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.

  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Create and Import Custom Functions in DataWeave

Create and Import Custom Functions in DataWeave

In this written and video tutorial, learn how to create custom functions in DataWeave and how to import the files and everything from the files.

By 
Abhishek Bathwal
·
Nov. 08, 21 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
19.8K 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

The article will showcase the creation of a file with custom functions and then show how to import them in DataWeave.

Creating a File With Custom Functions

A .dwl file for custom functions is created in src/main/resources under a folder called module.

src/main/resources — where to find the file

Importing Custom Functions in Dataweave

1. Import File

The custom functions file is under the module folder, so while importing, we need first to mention the folder name followed by the scope resolution operator (::) and then the file name.

Java
 
import <folder name>::<file name>


We are just importing the file, so we need to mention the file name followed by the scope resolution operator (::) then the function while calling the function. 

Java
 
<file name>::<function>


Calling only one function: 

Code screenshot showing importing file, file name, and function

Calling both the functions:

Code screenshot for both functions

2. Import Everything From File

We use an asterisk (*) followed by from keyword, which means import everything from the file to import everything.

Java
 
Import * from <folder name>::<file name>


Since we are importing everything this time, we don’t need to mention the file name while calling the functions, or else it will throw an error. 

Without file name:

Code screenshot: without file name

With file name: 

Code screeshot: with file name resulting in error


Notes

  1. We can directly create the functions file under the src/main/resource folder, but it’s best practice to create a folder and store the file in that.
  2. Naming conventions are very important.
Preferred
Not Preferred
camelCase -> customFunctions
snake_case -> custom_functions
PascalCase -> CustomFunctions
Kebab-case -> custom-functions 


Custom software MULE

Opinions expressed by DZone contributors are their own.

Related

  • Why 200 OK Is the Most Dangerous Lie in Enterprise Integration
  • Streaming vs In-Memory DataWeave: Designing for 1M+ Records Without Crashing
  • Optimizing MuleSoft Performance With HikariCP: A Complete Guide
  • Exploring Deployment Options in Mule 4

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