Posts

Mule4 - Dynamic Evaluate - Processor/Component

Image
 Dynamic Evaluate: The Dynamic Evaluate component/processor in Mule4 evaluates an expression to select DataWeave script , and then executes the new script to generate a result. This behavior enables you to dynamically select the script, instead of hardcoding it into the  Transform Message component based on condition. Usecase/scenario: 1. DataWeave script varies based on program id and its security id . 2. if there are 15 programs currently and may grow in future, In this scenario instead of writing if elseif condition based on program id and security id in a single dataweave script. 3. Modularize by  writing separate dwl script for each program id and security id combination. 4. Name each dataweave script such a way that program id and security id are part of it in order to resolve which script to dynamically evaluate at runtime. Example of dataweave without "Dynamic Evaluate" Component(illustration only): Example of dataweave with "Dynamic Evaluate" component: her...

DataWeave 2.0 Operator ~=

Image
 In DataWeave, the ~= operator determines if two values are similar, regardless of their type. for example: the string '123' and the number 123 are not equal, but they are recognized as similar or equal with  ~= operator. DataWeave:

Dataweave 2.0 read function

Image
 Converting String with escape characters (\), tab(\t), return (\r), new line (\n) to application/json. use read function. example

Dataweave 2.0 update function

Image
  Update the user data below. Usernames should be all lower case and the street should be   "Fiskargatan" (example from dataweave tutorial from mulesoft) Input payload { "username": "WASP", "name": "Lisbeth", "surname": "Salander", "location": { "address": { "street": "Lundagatan", "number": 9 }, "city": "Stockholm", "country": "Sweden" } } Dataweave Transformation %dw 2.0 import * from dw :: util :: Values output json --- payload update "username" with lower($) update [ "location" , "address" , field( "street" )] with "Fiskargatan" output { "username" : "wasp" , "name" : "Lisbeth" , "surname" : "Salander" , "location" : { "address...

Dataweave 2.0 - Pluck

Image
 Pluck is useful converting HashMap/Object into array of Objects.  pluck  iterates over an object and returns an array of keys, values, or indices from the object.

Dataweave 2.0(2.7) - typeOf

Image
 How to determine if the variable or payload type is String, Array, Number , Boolean or Object  using typeOf Object: String Number: Boolean: Array:

Mule4 - Resolving Database Date and DateTime Type Error while Inserting.

Let's see how to resolve error while inserting database date and datatime errors in Mule4 while inserting data into database. Column Declared as Date in database for the table example as follows: TRANDATE DATE DEFAULT '1970-01-01' NOT NULL, Dataweave : ( assuming the incoming  billing_date is coming as DateTime( example: "2024-02-06T11:02:05.237Z") and converting to Date in String format "yyyy-MM-dd" %dw 2.0 output application/json --- "billing_date": $.billing_date as DateTime {format: "yyyy-MM-dd'T'HH:mm:ss.SSSX"} as String {format : "yyyy-MM-dd"} , to convert RAML datetime type DB date time %dw 2.0 output application/json --- "date_updated" : $.date_updated as DateTime {         format : "yyyy-MM-dd'T'HH:mm:ss.SSSX"     } as DateTime {         format : "yyyy-MM-dd HH:mm:ss"     } error while executing :  "reason": "DB:QUERY_EXECUTION", "message...