MuleSoft DataWeave Use Case – Get last Monday of previous month

MuleSoft DataWeave is really powerful. We can implement complex data transformations. But in some cases, I think it is better to use DataWeave along with some of the proven Java libraries.

One such use case is to get last Monday of previous month. You may have to implement similar use cases in your project. I think the easiest way is to use joda-time library for this and similar use cases. Here is the example:

With Mule 3.x and DataWeave 1.0

Step 1: Include joda-time dependency in your project pom.xml

Step 2: Create a java class and a static function to get last Monday of the previous month. You can add more methods in this class based on the requirements.

Step 3: Create a global function in mule xml file

Step 4: Invoke this global function in DataWeave

With Mule 4.x and DataWeave 2.0

Step 1: Include joda-time dependency in your project pom.xml

Step 2: Create a java class and a static function to get last Monday of the previous month. You can add more methods in this class based on the requirements.

Step 3: Invoke this java static method in DataWeave (no need to create global function in this case)

Leave a Reply

Your email address will not be published. Required fields are marked *