KEMBAR78
MuleSoft DataWeave Functions | PDF | Software Architecture | Software
0% found this document useful (0 votes)
150 views4 pages

MuleSoft DataWeave Functions

The document contains examples of DataWeave code including functions, mappings, filtering, splitting strings, and generating XML. It shows how to map and transform JSON payload data, define and call functions, split and join strings, perform array operations, and generate XML output.

Uploaded by

Anoop Rahul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
150 views4 pages

MuleSoft DataWeave Functions

The document contains examples of DataWeave code including functions, mappings, filtering, splitting strings, and generating XML. It shows how to map and transform JSON payload data, define and call functions, split and join strings, perform array operations, and generate XML output.

Uploaded by

Anoop Rahul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

%dw 2.

0
output application/json
import * from dw::core::URL
var a = "is awesome"
fun myFunction1(arg1) = (if (arg1 == "harish") "Found" else "Not found")
fun myFunction2(arg1) = do {
var a = "inside func 2"
---
if (arg1 == a) "Found" else "Not found"

}
fun myFunction3(arg1) = arg1 match {
case isMatch1 : "Mule" -> "exaact Match"
case isMatch2 : "harish" -> "harish Match"
else -> "No match"
}
---
//using(b = "harish")
//payload.FirstName ++ " " ++ a ++ b
//myFunction1(b)
//myFunction2(a)
//myFunction3("harish")
//encodeURI(payload.message)
//payload.entries[1]
//payload.entries[?($."Company" == "Salesforce")]

/*payload.accountType.*users map {
"ACC Info" : $
}*/
//payload.accountType[0].users[1]
//payload.accountType[0].admins

items: payload.books map (item, index) -> {


book: item mapObject (value, key) -> {
(upper(key)): value
}
}

payload.accountType map(item1, index1) -> {


"accountType":
"users" : item1.users map(item2, index2) -> {
"Name" : item2.Name,
"CompanyName" : item2.Company
}

var a = [{
"Name": "Jordan",
"Company": "MuleSoft",
"Cities" : [
{
"Name" : "BZA",
"Pin" : 520011
},
{
"Name" : "HYD",
"Pin" : 4231
}
]
},
{
"Name": "Bob",
"Company": "Salesforce",
"Cities" : [
{
"Name" : "LEH",
"Pin" : 2288
},
{
"Name" : "POK",
"Pin" : 33778
}
]
}]

a map {
"NewName" : $.Name,
"New_COM" : $.Company,
"City_ARR" :
$.Cities map {
"City_Name": $
}
}

var b = {"accountType": [
{
"users":[
{
"Name" : "User ABC",
"Company" : "ABC Company"
},
{
"Name" : "User DEF",
"Company" : "DFF Company"
}
],
"admins": [
{
"Name" : "Admin ABC",
"Company" : "ABC Company"
},
{
"Name" : "Admin DEF",
"Company" : "DFF Company"
}
]
}] }
---
b mapObject {
"Current_OBJ" :
$ map {
"Users_Array" :
$.users map {
"UserName" : $.Name,
"UserCompany" : $.Company
},
"Admin_Array" :
$.admins map {
"AdminName" : $.Name,
"AdminCompany" : $.Company
}
}
}

var b = {
"accountType": [
{
"users":["HYD","BZA"],
"admins": ["POK","LEH"]
}
]
}
---
b.accountType map {
"Users":
$.users map ((item, index) ->
Name : item
)

var a = [1,2,3]
var b = [3,4,5]
---
//a -- b
a -- (a -- b)

var b = "((D1)){{v1}}||((D2)){{v2}}||((D3)){{v3}}|"
---
Drawings:
b splitBy ('||') map {
"Data" : ($ replace "(" with "" replace "}" with ""
splitBy (')){{'))[0],
"Version" : ($ replace "(" with "" replace "}" with ""
splitBy (')){{'))[1],
}

%dw 2.0
output application/xml

var a = [
{
"orderid":100,
"itemName":"harish"
},
{
"orderid":101,
"itemName":"vani"
}
]
---
order:
{(a map ((item, index) ->
item:
{
itenName: item.itemName,
ItenID: item.orderid
}
))}

====================================

<?xml version='1.0' encoding='UTF-8'?>


<order>
<item>
<itenName>harish</itenName>
<ItenID>100</ItenID>
</item>
<item>
<itenName>vani</itenName>
<ItenID>101</ItenID>
</item>
</order>
======================================

You might also like