Mulesoft: Introduction to DataWeave & Transform message Episode #2

on

|

views

and

comments

Hey Trailblazers, 🙂

Welcome back to Making an Integration Ranger Episode #2. Please find the agenda that we are going to learn today in Episode #2.

Access Event Properties

In some scenarios, we wanted to access the properties of the Event like the Query Parameters, URI parameters, Method, or other attributes. For example, get the values from the URL parameters in the request. You need to traverse the message like below

#[ message.attributes.queryParams.firstName as String ]

The Transform Message Component

The Transform (or Transform Message) component converts input data to a new output structure or format.

Drag & Drop view :

transform message component concept design center b3dc0

Preview

JSON file used for Demo

[
  {
    "Name": "Week 8 - Trigger Demo",
    "Phone": null,
    "Industry": null,
    "Rating": "Warm",
    "Description": "Before Update Account Name has been changed from Week 7 to Week 8 - Trigger Demo"
  },
  {
    "Name": "GenePoint",
    "Phone": "(650) 867-3450",
    "Industry": "Biotechnology",
    "Rating": "Cold",
    "Description": "Genomics company engaged in mapping and sequencing of the human genome and developing gene-based drugs"
  },
  {
    "Name": "United Oil & Gas, UK",
    "Phone": "+44 191 4956203",
    "Industry": "Energy",
    "Rating": null,
    "Description": null
  },
  {
    "Name": "United Oil & Gas, Singapore",
    "Phone": "(650) 450-8810",
    "Industry": "Energy",
    "Rating": null,
    "Description": null
  },
  {
    "Name": "Edge Communications",
    "Phone": "(512) 757-6000",
    "Industry": "Electronics",
    "Rating": "Hot",
    "Description": "Edge, founded in 1998, is a start-up based in Austin, TX. The company designs and manufactures a device to convert music from one digital format to another. Edge sells its product through retailers and its own website."
  },
  {
    "Name": "Week 8",
    "Phone": "(336) 222-7000",
    "Industry": "Banking",
    "Rating": "Warm",
    "Description": "Before Update Account Name has been changed from Burlington Textiles Corp of America to Week 8"
  },
  {
    "Name": "Pyramid Construction Inc.",
    "Phone": "(014) 427-4427",
    "Industry": "Construction",
    "Rating": null,
    "Description": null
  },
  {
    "Name": "Dickenson plc",
    "Phone": "(785) 241-6200",
    "Industry": "Consulting",
    "Rating": null,
    "Description": null
  },
  {
    "Name": "Grand Hotels & Resorts Ltd",
    "Phone": "(312) 596-1000",
    "Industry": "Hospitality",
    "Rating": "Warm",
    "Description": "Chain of hotels and resorts across the US, UK, Eastern Europe, Japan, and SE Asia."
  },
  {
    "Name": "Express Logistics and Transport",
    "Phone": "(503) 421-7800",
    "Industry": "Transportation",
    "Rating": "Cold",
    "Description": "Commerical logistics and transportation company."
  }
]

DataWeave code used in Demo

%dw 2.0
output application/xml

import dw::core::Strings
import camelize, capitalize from dw::core::Strings
import * from dw::core::Strings

var myvar = "amit singh"

var toUpper = (aString) -> 
	if(aString=="Hot")
		"too hot"
	else
		"too Cold"
		
fun capit(rating:String) = 
	if(rating == "Hot")
		"Amit"
	else 
		"Singh"
	
---

accounts : {
	(payload map () ->{
		account @(name : $.Name) : $.Description,
		Phone : $.Phone,
		name : toUpper(myvar),
		name : capit(myvar)
	})
}
/*
accounts_1 : {
		(payload map () ->{
			accounts : {
				account : $
			}	
		})
	} */
	

Complete flow from Day 2

Watch all this in Action:

Sharing is caring. #KeepLearning #KeepBlazing #RoadToIntegrationRanger #Mulesoft

References

Amit Singh
Amit Singhhttps://www.pantherschools.com/
Amit Singh aka @sfdcpanther/pantherschools, a Salesforce Technical Architect, Consultant with over 8+ years of experience in Salesforce technology. 21x Certified. Blogger, Speaker, and Instructor. DevSecOps Champion
Share this

Leave a review

Excellent

SUBSCRIBE-US

Book a 1:1 Call

Must-read

How to Utilize Salesforce CLI sf (v2)

The Salesforce CLI is not just a tool; it’s the cornerstone of development on the Salesforce Platform. It’s your go-to for building, testing, deploying, and more. As one of the most important development tools in our ecosystem

Save the day of a Developer with Apex Log Analyzer

Table of Contents What is Apex Log Analyzer? Apex Log Analyzer, a tool designed with Salesforce developers in mind, is here to simplify and accelerate your...

Salesforce PodCast

Introduction Hey Everyone, Welcome to my podcast, the first-ever podcast in India for Salesforce professionals. Achievement We are happy to announce that we have been selected as Top...

Recent articles

More like this

LEAVE A REPLY

Please enter your comment!
Please enter your name here

MuleSoft, a part of Salesforce, is a prominent player in the integration and API management space. Its flagship product, the Anypoint Platform, is designed to streamline the way businesses connect and manage their applications, data, and devices. Here’s a detailed look at MuleSoft and what it offersMulesoft: Introduction to DataWeave & Transform message Episode #2
5/5

Stuck in coding limbo?

Our courses unlock your tech potential