0% found this document useful (0 votes)
18 views

Datawave (2)

The document outlines various error handling techniques and data transformations using DataWeave (DW) 2.0. It includes details on error levels, default error handling, global error handlers, and specific examples of data mappings and transformations. The document also provides input-output pairs demonstrating different mapping strategies for JSON and array data structures.

Uploaded by

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

Datawave (2)

The document outlines various error handling techniques and data transformations using DataWeave (DW) 2.0. It includes details on error levels, default error handling, global error handlers, and specific examples of data mappings and transformations. The document also provides input-output pairs demonstrating different mapping strategies for JSON and array data structures.

Uploaded by

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

ERRROR HANDLING:::::

1)How many levels we can handel the errors?


2)what is default error handling at project level?
3)what is the customer global error handler?
4)what are the flow level exception handling?
5)what is error Type?
6)what happen some error not found in error handler what type of error it will give?

-------------------------------------------
whenever error occured in flow an error object is created
it contains error.description,error.errorType, errortype is nothing but combination of
Namespace and Identifier
EG:: DB:connectivity,http:unauthorized

1) Input:::
"xyz,abc,apq"
OutPut:::

{
"A1":"xyz",
"A2":"abc",
"A3":"apq"
}
Mpping:::

%dw 2.0
output application/json
---
payload splitBy(",")

we need to convert text to arry. split(",")


Result:: ["xyz","abc","apq"]
result in arry formate we need to do some operation, we need to store a1,a2,a3 in varibule.

%dw 2.0
output application/json
var D =["A1","A2","A3"]
---
payload map((D[$$]):$) reduce (item,acc={})-> acc ++ item

-------------------------------------------------------------------------
2) Input:::
[{
"A1":"N",
"A2":"sathish"
},{
"A1":"reddy",
"A2":"SSSS"
}]
OutPut:::

{
"N":"satish",
"reddy":"SSSS"
}
Mpping::::

%dw 2.0
output application/json
---
payload map((item,index)->(item.A1):item.A2) reduce (item,acc={})-> acc ++ item
///////// OR ///////
%dw 2.0
output application/json
---
payload map(($.A1):$.A2) reduce (item,acc={})-> acc ++ item
---------------------------------------------------------------------------
3) Input:::

{
"pratice":[1,2,3,4,5]
}
Output:::
[2,3,4,5,6]
Mapping:::

%dw 2.0
output application/json
---
payload.message map ((item, index) -> item+1)
//////////OR/////////
%dw 2.0
output application/json
---
payload.message map ($+1)
---------------------------------------------------------------------------
4) Input:::
[
{"Id":1,"name":"satish"},
{"Id":2,"name":"reddy"},
{"Id":3,"name":"reddy"}
]

want only Id
Output:::

[
1,
2,
3
]
Mapping:::

%dw 2.0
output application/json
---
payload map ($.Id)
-----------------------------------------------------
4)Input:::
[{
"name":"satish",
"jobs":[{"role": "developer"},
{"role": "tester"},
{"role": "actor"}
]
},{
"name":"satish",
"jobs":[{"role": "doctor"},
{"role": "teacher"},
{"role": "Roller"}
]
}]
Output:::
[
{
"name": "satish",
"jobs": [
{
"Id": 0,
"role": "developer"
},
{
"Id": 1,
"role": "tester"
},
{
"Id": 2,
"role": "actor"
}
]
},
{
"name": "satish",
"jobs": [
{
"Id": 0,
"role": "doctor"
},
{
"Id": 1,
"role": "teacher"
},
{
"Id": 2,
"role": "Roller"
}
]
}
]
Mapping::::

%dw 2.0
output application/json
---
payload map(item,index)->{
"name":item.name,
"jobs":item.jobs map(item,index)->{
Id:index,
role:item.role
}
}

5)Input:::

[1,2,4,7,9,10,99,100,44,77,22]
Output:::
Deviible By 2

Mppaing:::
%dw 2.0
output application/json
---
Diveded By 2::
payload filter (item, index) -> (mod(item,2))==0,
ODD Numbers::
payload filter ((item, index) -> isOdd(item))
Even Numbers::
payload filter ((item, index) -> isEven(item))
ODD Index::
payload filter ((item, index) -> isOdd(index))
Even Index::
payload filter ((item, index) -> isOdd(index))

6) Input::
[
{
"Id": 1,
"Statuse": "Load"
},
{
"Id":2,
"Statuse": "AIM"
},
{
"Id": 3,
"Statuse": "Shut"
}
]
OUTPUT:::
[
{
"Id": 1,
"Statuse": "Load"
},
{
"Id": 2,
"Statuse": "AIM"
}
]
Mapping:::
%dw 2.0
output application/json
---
payload filter ((item, index) -> item.Id !=3 )
7) INPUT::
[
"satish",
"sita",
"jshd",
"jwkfj"
]
Output:::
[
"jshd",
"jwkfj"
]
Mapping:::

%dw 2.0
output application/json
var F=["satish","sita"]
---
//payload filter ((item, index) -> !(item == "satish" or item == "sita" or item == "jshd"))
payload filter (item, index) -> !(item == F[0] or item == F[1] )
8)
Input::

{
"a": "satish",
"b":"sita",
"c":"jshd",
"d":"jwkfj",
"e": null
}
Output:::
{
"A": "SATISH",
"B": "SITA",
"C": "JSHD",
"D": "JWKFJ"
}
MAPPING:::

payload mapObject ((value, key, index) -> if(value != null)((upper(key)):upper(value)) else


{})

9)
INPUT:::

{
"a": "satish",
"b":"sita",
"c":"jshd",
"d":"jwkfj",
"e": "null"
}
OUPUT:::

[
["a", "satish"],
["b","sita"],
["c","jshd"],
["d","jwkfj"],
["e", "null"]
]
MAPPING:::

%dw 2.0
output application/json
---
//payload pluck ((value, key, index)-> (upper(key)):upper(value))
payload pluck ((value, key, index) -> [key,value])

10)
INPUT::

{
"a": "satish",
"b":"sita",
"c":"jshd",
"d":"jwkfj",
"e": "null"
}
Output::::

[
{
"A": "SATISH"
},
{
"B": "SITA"
},
{
"C": "JSHD"
},
{
"D": "JWKFJ"
},
{
"E": "NULL"
}
]
MAPPING:::

%dw 2.0
output application/json
var F=["satish","sita"]
---
payload pluck ((value, key, index)-> (upper(key)):upper(value))
//payload pluck ((value, key, index) -> [key,value])

11)
INPUT:::
surename=nemalidinne;
name=sathish;
middlename=reddy;
rank=312
OUTPUT:::

{
"surename": "nemalidinne",
"name": "sathish",
"middlename": "reddy",
"rank": "312"
}
Mapping:::
%dw 2.0
output application/json
---
payload splitBy(";") map ((item, index) -> item splitBy ("=")) reduce ((item, accumulator=
{}) ->accumulator++(item[0]):item[1] )
OR
payload splitBy ";" map ((item, index) ->item splitBy "=" ) map ((item, index) ->
(item[0]):item[1] )reduce($$++$)
-------------------------------------------------------------
12)
INPUT:::

[
{
"product name":"bread",
"ExpairyDate":"11/01/2011",
"Price": 40
},
{
"product name":"Apple",
"ExpairyDate":"22/12/2012",
"Price": 60
},
{
"product name":"wine",
"ExpairyDate":"13/11/2022",
"Price": 30
},
{
"product name":"milk",
"ExpairyDate":"12/11/2039",
"Price": 140
}
]
OUTPUT::::
[
30,
140
]
Mapping:::
%dw 2.0
output application/json
var TodayDate = now() as Date {format:"dd/MM/yyyy"}
var DD = payload filter $.ExpairyDate>TodayDate
---
(payload filter $.ExpairyDate>TodayDate).Price
13)
INPUT:::
{"ID":"123_(456)_(789)"}
OUTPUT::
789
MAPPING:::

%dw 2.0
output application/json
---
((payload.ID splitBy("_"))[2] replace "(" with "" replace ")" with "") as Number
14)
INPUT::
[{
"Id": 1234,
"Name": "salary Account",
"Type": "Salary",
"chaild account":[
{
"Name":"personal",
"Type":"Self",
"Id": 987
},{
"Name":"Loan Account",
"Type":"Loan",
"Id": 654
}
]
}]
OUTPUT::
[
{
"ID": 1234,
"Name": "salary Account"
},
{
"Name": "personal",
"ID": 987
},
{
"Name": "Loan Account",
"ID": 654
}
]
MAPPING::

%dw 2.0
output application/json
var S = payload map(item,index)->{
"ID":item.Id,
"Name":item.Name
}
var R=flatten(payload.chaildaccount map(item)-> item map(item2)->{
"Name":item2.Name,
"ID":item2.Id
})
---
S ++ R
---------------------------------------------------------------------
14)
INPUT:::
"mulesoft,12"
OUTPUT:::
"SDAR , 90"
Mapping:::
%dw 2.0
output application/json
fun first(item1:String,item2:Number)=
upper(item1) ++ " , " ++ item2*10
---
first("sdar",9)

15)
INPUT:::
{
"parent":{
"OrderID":"123",
"price":"12",
"Chaild1":{
"OrderID": "456",
"price": "34"
},
"Chaild2":{
"OrderID": "789",
"price": "27"
}
}
}
OUTPUT:::
sum of all the Pricess.
MAPPING:::
%dw 2.0
output application/json
---
payload.parent..price reduce($ + $$)
sum (payload..price)
------------------------------------------
16)
INPUT:::
[1,33,56,74,989,45,89]
OUTPUT:::::
Assinding Order or desinding Order
MAPPING:::
%dw 2.0
output application/json
---
//(payload orderBy $) [-1 to 0]
payload orderBy -$
17)
INPUT:::
[{
"name": "satish",
"jobs":[{
"type": "Developer"},
{
"type":"tester"
},
{
"type":"actor"
}
]},{
"name":"Anil",
"jobs":[{
"type":"farmer"

},{
"type":"Leader"
},{
"type":"Traveler"
}
]}]
OUTPUT:::
[
{
"id header": 1,
"name": "satish",
"jobs": [
{
"id chaild": 200,
"type": "Developer"
},
{
"id chaild": 201,
"type": "tester"
},
{
"id chaild": 202,
"type": "actor"
}
]
},
{
"id header": 2,
"name": "Anil",
"jobs": [
{
"id chaild": 200,
"type": "farmer"
},
{
"id chaild": 201,
"type": "Leader"
},
{
"id chaild": 202,
"type": "Traveler"
}
]
}
]
MAPPING:::
%dw 2.0
output application/json
---
flatten(payload map ((item, index) -> {
"id header":index+1,
"name":item.name,
"jobs": item.jobs map(data,index1)->{
"id chaild":index1+200,
"type":data."type"
}
}))
18)
INPUT:::
{
"product_name": [{
"Id": 123,
"name": "satish"

},
{
"id": 456,
"name": "reddy"
},
{
"id": 789,
"name": "nemalidinne"
}
],
"product_price": [{
"id": 123,
"price": 1000
},
{
"id": 456,
"price": 2000
},
{
"id": 789,
"price": 3000
}
]
}
OUTPUT:::
[
{
"id": 123,
"price": 1000
},
{
"id": 456,
"price": 2000
},
{
"id": 789,
"price": 3000
}
]
MAPPING::
%dw 2.0
output application/json
---
flatten(payload.product_name map(item1)->payload.product_price filter ((item2,index) -
>item2.id==item1.id ))
19)
INPUT:::
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10
]
OUTPUT:::
[
0,
2,
4,
6,
8,
10,
[
1,
3,
5,
7,
9
]
]
MAPPING:::
%dw 2.0
output application/json
var S = payload map if(isEven($)) {even:$} else{odd:$}
var G = payload map if(mod ($, 2) == 0) {even:$} else{odd:$}
---
G.even + G.odd

//S.odd + S.even
20)
INPUT:::
[{
"CartPlace": "Order_Complete",
"currency": "INR",
"subtotal": 13,
"discount Amount": 2,
"emailAddrees": "[email protected]",
"orderId": "A123B",
"ShippingAmount": "7_34",
"Shipping_date": "01/10/2022",
"ShippingDetails": "fedex"
}, {
"CartPlace": "Order_Complete",
"currency": "USA",
"subtotal": 56,
"discount Amount": 3,
"emailAddrees": "[email protected]",
"orderId": "A123B",
"ShippingAmount": "07_4",
"Shipping_date": "01/12/2022",
"ShippingDetails": "Demart"
}]
OUTPUT:::
1) convert to csv,
2)remove email and currency,
3) separator with |,
4) leftPad 14,
MAPPING:::
%dw 2.0
import * from dw::core::Strings
output application/csv header=false,separator= "|"
var s=payload map ($ -"currency" - "emailAddrees")
var R= payload map (data)->data mapObject ((value, key, index) -> (key):leftPad(value,14,7))
---
R ++ s
-------------------------------------------------------------------------------
21)
INPUT:::
DISPLAYOnly Date using now function
Output::
"18/10/2022"
Mapping::::
%dw 2.0
output application/json
---
now() as String{format:"dd/MM/yyyy"}
------------------------------------------
22)
Input::
{
"A":[1,2,3,4],
"B":[5,6,[7,8,9],0]
}

CONVERT AS SINGLE ARRY


Output:::
[
5,
6,
7,
8,
9,
0,
1,
2,
3,
4
]
MAPPINGG:::
%dw 2.0
output application/json
---
flatten(payload.B ++ payload.A)
----------------------------------------
23)
INPUT:::
[1,2,3,4,5]
Output:::
[
2,
4,
6,
8,
10
]
Mapping:::
%dw 2.0
output application/json
---
payload map $*2
-----------------------------
24)
INPUT::
[1,2,3,4,5]
OUTPUT:::
15
ADD ALL Numbers
MAPPING::::
%dw 2.0
output application/json
---
//payload reduce ((item, accumulator=0) ->accumulator+item )
payload reduce($+$$)
---------------------------------------
24)
INPUT:::
5
FIND THE FACTORIAL OF 5
OUTPUT:::
120
MAPPING:::
%dw 2.0
output application/json
fun fact(n)=if(n==1 or n==0) 1 else n *fact(n-1)
---
A
--------------------------------------------------
25)
INPUT::
number
NEED TO FIND EVEN OR ODD Number
OTPUT:::
"IS EVEN" OR "IS ODD"
MAPPING::
%dw 2.0
output application/json
fun S(payload)= if((payload mod 2)==0) payload ++"," ++"is even number" else payload
++","++"is Odd number"
---
if((payload mod 2) ==0) "is even" else "is Odd"
-------------------------------------------------------
26)
INPUT::::
[1,2,3,4,5,6,7,8,9,0]
OUTPUT:::
{
"even": [
2,
4,
6,
8,
0
],
"odd": [
1,
3,
5,
7,
9
]
}
MAPPING:::
%dw 2.0
output application/json
fun S(payload)= if((payload mod 2)==0) payload ++"," ++"is even number" else payload
++","++"is Odd number"
var U = payload filter ((item, index) -> (item mod 2) ==0)
var P = payload filter ((item, index) ->(item mod 2) ==1 )
---
//payload map (( $ mod 2)==0)
{
"even":U,
"odd": P
}
---------------------------------------------
27)
INPUT:::
[{
"name":"satish",
"age": 27
},{
"name":"anil",
"age": 23
},{
"name":"srinu",
"age":55
},
{
"name":"ravana",
"age": 45
}]
OUTPUT:::
[
{
"name": "anil",
"age": 23
},
{
"name": "srinu",
"age": 55
},
{
"name": "ravana",
"age": 45
}
]
MAPPING:::
%dw 2.0
output application/json
---
payload filter ((item, index) -> !(item.age==27) )
//payload groupBy ((item, index) -> (item.age == 27) )
--------------------------------------------------------
28)
INPUT:::{
"Date": "20221015135455"
}
OUTPUT:::
{
"DATE": "2022-10-15T13:54:55"
}
Mapping::::
%dw 2.0
output application/json
fun fact(n)=if(n==1 or n==0) 1 else n*fact(n-1)
var date=payload.Date
---
"DATE":payload.Date as LocalDateTime {format:"yyyyMMddHHmmss"} as String{format:"yyyy-MM-
dd'T'HH:mm:ss"}
//{"DATE":(date[0 to 3]) ++"-"++ date[4 to 5] ++"-"++ date[6 to 7]++ "T"++ date[8 to 9]++"-
"++ date[10 to 11]++ "-" ++ date[12 to 13]}
--------------------------------------------------------------------------------
29)
INPUT::::
[{
"UserId":1,
"ServiceNumber":"aa",
"Location":"Mumbai"
},{
"UserId":2,
"ServiceNumber":"BB",
"Location":"HYd"
},{
"UserId":3,
"ServiceNumber":"BB",
"Location":"narasaraopet"
},{
"UserId":4,
"ServiceNumber":"GG",
"Location":"Guntur"
},{
"UserId":5,
"ServiceNumber":"DD",
"Location":"HYd"
}]
OUTPUT::::
[
{
"ServiceNumber": "aa",
"details": [
{
"UserId": 1,
"Location": "Mumbai"
}
]
},
{
"ServiceNumber": "BB",
"details": [
{
"UserId": 2,
"Location": "HYd"
},
{
"UserId": 3,
"Location": "narasaraopet"
}
]
},
{
"ServiceNumber": "GG",
"details": [
{
"UserId": 4,
"Location": "Guntur"
}
]
},
{
"ServiceNumber": "DD",
"details": [
{
"UserId": 5,
"Location": "HYd"
}
]
}
]
MAPPING::::
%dw 2.0
output application/json
fun fact(n)=if(n==1 or n==0) 1 else n*fact(n-1)
var date=payload.Date
---
payload groupBy ((item, index) -> item.ServiceNumber) pluck ((value, key, index) ->{
ServiceNumber:key,details:value map ((item, index) ->
{
"UserId":item.UserId,
"Location":item.Location
})
})
29)
INPUT:::
<?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</description>
</book>
<book id="bk103">
<author>Corets, Eva</author>
<title>Maeve Ascendant</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-11-17</publish_date>
<description>After the collapse of a nanotechnology
society in England, the young survivors lay the
foundation for a new society.</description>
</book>
<book id="bk104">
<author>Corets, Eva</author>
<title>Oberon's Legacy</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2001-03-10</publish_date>
<description>In post-apocalypse England, the mysterious
agent known only as Oberon helps to create a new life
for the inhabitants of London. Sequel to Maeve
Ascendant.</description>
</book>
<book id="bk105">
<author>Corets, Eva</author>
<title>The Sundered Grail</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2001-09-10</publish_date>
<description>The two daughters of Maeve, half-sisters,
battle one another for control of England. Sequel to
Oberon's Legacy.</description>
</book>
<book id="bk106">
<author>Randall, Cynthia</author>
<title>Lover Birds</title>
<genre>Romance</genre>
<price>4.95</price>
<publish_date>2000-09-02</publish_date>
<description>When Carla meets Paul at an ornithology
conference, tempers fly as feathers get ruffled.</description>
</book>
<book id="bk107">
<author>Thurman, Paula</author>
<title>Splish Splash</title>
<genre>Romance</genre>
<price>4.95</price>
<publish_date>2000-11-02</publish_date>
<description>A deep sea diver finds true love twenty
thousand leagues beneath the sea.</description>
</book>
<book id="bk108">
<author>Knorr, Stefan</author>
<title>Creepy Crawlies</title>
<genre>Horror</genre>
<price>4.95</price>
<publish_date>2000-12-06</publish_date>
<description>An anthology of horror stories about roaches,
centipedes, scorpions and other insects.</description>
</book>
<book id="bk109">
<author>Kress, Peter</author>
<title>Paradox Lost</title>
<genre>Science Fiction</genre>
<price>6.95</price>
<publish_date>2000-11-02</publish_date>
<description>After an inadvertant trip through a Heisenberg
Uncertainty Device, James Salway discovers the problems
of being quantum.</description>
</book>
<book id="bk110">
<author>O'Brien, Tim</author>
<title>Microsoft .NET: The Programming Bible</title>
<genre>Computer</genre>
<price>36.95</price>
<publish_date>2000-12-09</publish_date>
<description>Microsoft's .NET initiative is explored in
detail in this deep programmer's reference.</description>
</book>
<book id="bk111">
<author>O'Brien, Tim</author>
<title>MSXML3: A Comprehensive Guide</title>
<genre>Computer</genre>
<price>36.95</price>
<publish_date>2000-12-01</publish_date>
<description>The Microsoft MSXML3 parser is covered in
detail, with attention to XML DOM interfaces, XSLT processing,
SAX and more.</description>
</book>
<book id="bk112">
<author>Galos, Mike</author>
<title>Visual Studio 7: A Comprehensive Guide</title>
<genre>Computer</genre>
<price>49.95</price>
<publish_date>2001-04-16</publish_date>
<description>Microsoft Visual Studio 7 is explored in depth,
looking at how Visual Basic, Visual C++, C#, and ASP+ are
integrated into a comprehensive development
environment.</description>
</book>
</catalog>
OUTPUT::::
[
{
"author": "Gambardella, Matthew",
"title": "XML Developer's Guide"
},
{
"author": "Ralls, Kim",
"title": "Midnight Rain"
},
{
"author": "Corets, Eva",
"title": "Maeve Ascendant"
},
{
"author": "Corets, Eva",
"title": "Oberon's Legacy"
},
{
"author": "Corets, Eva",
"title": "The Sundered Grail"
},
{
"author": "Randall, Cynthia",
"title": "Lover Birds"
},
{
"author": "Thurman, Paula",
"title": "Splish Splash"
},
{
"author": "Knorr, Stefan",
"title": "Creepy Crawlies"
},
{
"author": "Kress, Peter",
"title": "Paradox Lost"
},
{
"author": "O'Brien, Tim",
"title": "Microsoft .NET: The Programming Bible"
},
{
"author": "O'Brien, Tim",
"title": "MSXML3: A Comprehensive Guide"
},
{
"author": "Galos, Mike",
"title": "Visual Studio 7: A Comprehensive Guide"
}
]
MAPPING::::
%dw 2.0
output application/json
var S=payload.catalog.book.author
var R=payload.catalog.book.title
---
payload.catalog pluck ((value, key, index) ->(key):value ) map ((item, index) -> {
"author":item.book.author,
"title":item.book.title
})

---------------------------------------------------------
30)
INPUT:::
[1,12,23,34]
OUTPUT::::
[
{
"values": 1,
"v *10": 10,
"index": 0,
"The value After": 12
},
{
"values": 12,
"v *10": 120,
"index": 1,
"The value After": 23
},
{
"values": 23,
"v *10": 230,
"index": 2,
"The value After": 34
},
{
"values": 34,
"v *10": 340,
"index": 3,
"The value After": null
}
]
MAPPING:::::
%dw 2.0
output application/json
---
payload map ((item, index) ->{
"values":item,
"v *10":item *10,
"index":index,
"The value After": payload[index+1]
} )

31)INPUT:::
{
"Tablelist":[
{
"Name": "nemalidinne_satish_reddy"
},{
"Name": "nemalidinne_ANIL_reddy"
},{
"Name": "Madhinnene_SAI_Chowdery"
},{
"Name": "Vadlamudi_Singhaia_Chowdary"
},{
"Name": "Vadlamudi_vamsi_Chowdary"
}
]
}
OUTPUT:::
[
{
"index": 20,
"J": "nemalidinne",
"K": [
{
"S": "nemalidinne",
"T": "satish_reddy"
},
{
"S": "nemalidinne",
"T": "ANIL_reddy"
}
]
},
{
"index": 21,
"J": "Madhinnene",
"K": [
{
"S": "Madhinnene",
"T": "SAI_Chowdery"
}
]
},
{
"index": 22,
"J": "Vadlamudi",
"K": [
{
"S": "Vadlamudi",
"T": "Singhaia_Chowdary"
},
{
"S": "Vadlamudi",
"T": "vamsi_Chowdary"
}
]
}
]
MAPPING:::
%dw 2.0
output application/json
---
(payload.Tablelist map ((item, index) ->
using (data=item.Name splitBy("_"))
{
"S":data [0],
"T":data [1 to 2] joinBy "_"
} ))groupBy ((item, index) -> item.S) pluck ((value, key, index) -> {
"index":index+20,
"J":key,
"K":value,

})

32))
INPUT:::
[{
"val":[
"1",
"2",
"3",
"4"
],
"ID":[
"a",
"b",
"c",
"d"
]
},{
"val":[
"1",
"2",
"3",
"4"
],
"ID":[
"a",
"b",
"c",
"d"
]
},{
"val":[
"1",
"2",
"3",
"4"
],
"ID":[
"a",
"b",
"c",
"d"
]
},{
"val":[
"1",
"2",
"3",
"4"
],
"ID":[
"a",
"b",
"c",
"d"
]
}
]
OUTPUT:::
[
{
"ID": "a",
"VAL": 4
},
{
"ID": "b",
"VAL": 8
},
{
"ID": "c",
"VAL": 12
},
{
"ID": "d",
"VAL": 16
}
]
MAPPING::::
%dw 2.0
output application/json
---
flatten(payload map ((item, index) ->item.ID map ((item1, index1) ->{
ID:item1,
Val:item.val[index1]
} ))) groupBy ((item, index) ->item.ID )pluck ((value, key, index) ->{
ID:key,
VAL:value.Val reduce($+$$)
})

33)INPUT::::
[{
"ordernumber": 123,
"itemnumber": "111",
"RequistDate": "2022-05-26"
},{
"ordernumber": 456,
"itemnumber": "187",
"RequistDate": "2022-06-30"
},{
"ordernumber": 789,
"itemnumber": "0987",
"RequistDate": "2021-06-26"
},{
"ordernumber": 312,
"itemnumber": "312",
"RequistDate": "2022-05-27"
},{
"ordernumber": 123,
"itemnumber": "111",
"RequistDate": "2022-05-28"
}]
OUTPUT:::
[
{
"OrderNumber": "123",
"LineItem": [
{
"RequistDate": "2022-05-26",
"ItemNumber": "111"
}
]
},
{
"OrderNumber": "456",
"LineItem": [
{
"RequistDate": "2022-06-30",
"ItemNumber": "187"
}
]
},
{
"OrderNumber": "789",
"LineItem": [
{
"RequistDate": "2021-06-26",
"ItemNumber": "0987"
}
]
},
{
"OrderNumber": "312",
"LineItem": [
{
"RequistDate": "2022-05-27",
"ItemNumber": "312"
}
]
}
]
MAPPING::::

%dw 2.0
output application/json
---
payload distinctBy $.ordernumber groupBy ((item, index) -> item.ordernumber)pluck ((value,
key, index) ->{
"orderNumber":key,
"LineItems":value map ((item, index) -> {

"RequistDate":item.RequistDate,
"itemNumber":item.itemnumber
})
} )
34)
INPUT:::
{
"name":"sathishReddy",
"Place":"Hyderabad",
"Job":"Software"
}
OUTPUT:::
{
"name": "sathishReddy",
"Place": "nrt",
"Job": "Software"
}
Mapping:::
%dw 2.0
output application/json
---
/*payload mapObject((value, key, index) ->{
(key):if(value=="Hyderabad") "A.muppalla" else value
} )*/
payload update {
case satish at .Place -> "nrt"
}
35)
INPUT:::
{
"businessunits": [
{
"code":"IT",
"name":"Information Technology"
}, {
"code":"BPS",
"name":"Bussiness Processing Services"
}, {
"code":"BPO",
"name":"Bussiness Processing Services"
}
],
"Division":[
{
"code":"AM",
"name":"Administation",
"business":"IT"
},{
"code":"TS",
"name":"Technical Services",
"business":"IT"
},{
"code":"ES",
"name":"Administation",
"business":"BPO"
},{
"code":"PS",
"name":"Photoshop Serices",
"business":"PSO"
}
]
}
OUTPUT:::
[
{
"name": "Information Technology",
"code": "IT",
"Dname": "Administation",
"Dcode": "AM"
},
{
"name": "Information Technology",
"code": "IT",
"Dname": "Technical Services",
"Dcode": "TS"
},
{
"name": "Bussiness Processing Services",
"code": "BPS",
"Dname": null,
"Dcode": null
},
{
"name": "Bussiness Processing Services",
"code": "BPO",
"Dname": "Administation",
"Dcode": "ES"
}
]
MAPPING::::
%dw 2.0
output application/json
import * from dw::core::Arrays
var A= payload.businessunits
var B= payload.Division
---
leftJoin(A,B,(A)->A.code,(B)->B.business)map ((item, index) ->{
"name":item.l.name,
"code":item.l.code,
"Dname":item.r.name,
"Dcode":item.r.code
} )
36)
INPUT::
[{
"resource":"SalesOrgToMap",
"resourceId":"110",
"destination":{
"agialoftinstancename":"APAC",
"url":"https://test.appis.com:37158/s1/"
},

"destnationType":"SystemAPI",
"perameters":{
"OrgCode":"RD_ID",
"SalesOrg":"12345",
"interfacedID":"CreateContractInterface"
}
},
{
"resource":"SalesOrgToMap",
"resourceId":"1101",
"destination":{
"agialoftinstancename":"APAC",
"url":"https://test.appis.com:37158/s1/"
},
"destnationType":"SystemAPI",
"perameters":{
"OrgCode":"RD_LD",
"SalesOrg":"09886",
"interfacedID":"CrReateContractInterface"
}}]

OutPUT::::
[
{
"resource": "SalesOrgToMap",
"resourceId": "110",
"destination": {
"agialoftinstancename": "APAC",
"url": "https://test.appis.com:37158/s1/"
},
"destnationType": "SystemAPI",
"perameters": {
"OrgCode": "RD_ID",
"SalesOrg": "12345",
"interfacedID": "CreateContractInterface"
}
},
{
"resource": "SalesOrgToMap",
"resourceId": "1101",
"destination": {
"agialoftinstancename": "APAC",
"url": "https://test.appis.com:37158/s1/"
},
"destnationType": "SystemAPI",
"perameters": {
"OrgCode": "RD_LD",
"SalesOrg": "09886",
"interfacedID": "CrReateContractInterface"
}
}
]
Mapping:::
%dw 2.0
output application/json
var S={
"OrgCode":"RD_ID",
"SalesOrg":"12345"
}
fun Checklist(dataitem,S)=do{ var temp=(S mapObject ((value, key, index) -> data :
dataitem.perameters[key] == S[key])).*data
---
temp == temp filter($!=false)
}
---
payload filter ((item, index) ->
Checklist(item,S)
)
37)
INPUT:::
{
"communication": [
{
"sourceId": "226",
"domain": "mule",
"customers": [
{
"sType": "wire",
"mode": "EMAIL",
"category": "DAY_AFTER_EXPIRE",
"ctn": [
"771779"
],
"Type": "I",
"langPreference": "EN",
"eventSentTime": "11-16-2022T12:44:26 +0000",
"accNo": "1770"
}
],
"destination": "SF",
"Req": true
}
]
}
OUTPUT::
[
{
"sourceID": "226",
"domain": "mule",
"customers": [
{
"sType": "wire",
"mode": "EMAIL",
"category": "DAY_AFTER_EXPIRE",
"ctn": [
"771779"
],
"Type": "I",
"langPreference": "EN",
"eventSentTime": "11-16-2022T12:44:26 +0000",
"accNo": "1770"
}
],
"notifications": [
{
"eventType": ""
}
],
"destination": "SFDC",
"req": true,
"accountSreq": true
}
]
MAPPING:::

38)
INPUT::

[{
"name":"satish",
"ID": 312,
"Tag":"hero"
},
{
"logic":"hjw",
"magic":"hgd"
}]
OUTPUT:::
[
{
"name": "ANIL",
"ID": 123,
"Tag": "SUPERHERO"
},
{
"logic": "datawave",
"magic": "jka"
}
]
MAPPING:::
%dw 2.0
import update,field from dw::util::Values
output application/json
---
payload update "name" with upper("anil") update "logic" with "datawave" update "ID" with 123
update "magic" with "jka" update "Tag" with upper( ("Super" ++ "hero"))

39)
INPUT:::
[{"name": "Ken", "age": 30},
{"name": "Tomo", "age": 70},
{"name": "Kajika", "age": 10}]
OUTPUT::::
[
{
"name": "SATISH",
"age": 77
},
{
"name": "Tomo (hdagf)",
"age": 42
},
{
"name": "Kajika",
"age": 10
}
]
MAPPING:::
%dw 2.0
output application/json
---
payload map(item)->item update {
case AA at .age if(AA == 30) -> 77
case SS at .age if(SS==70)->42
case ZZ at .name if(ZZ=="Tomo")-> ZZ ++ " (hdagf)"
case XX at .name if(XX=="Ken")-> upper("satish")
}
40)
INPUT:::

{
"message": "helloabc",
"name":"hellodce"
}
Output:::
"acde"
Mapping:::
%dw 2.0
output application/json
import * from dw::core::Strings
var A=payload.message [5 to 7] remove "b"
var B=payload.name[5 to 7] remove "c"
---
A ++ B
41)
INPUT::
[{
"business":{
"ID":"rel",
"desc":"rel industry",
"industry":{
"ID":"manufacture",
"desc":"manufacturing",
"Businessline":{
"ID":"residential",
"desc":"residential manufacture",
"facility":{
"ID":"mumbai",
"desc":"mumbai location"
}
}
}
}
}]
OUTPUT:::
{
"asset": [
{
"key": "rel",
"desc": "rel industry"
},
{
"key": "manufacture",
"desc": "manufacturing",
"parent": [
"rel"
]
},
{
"key": "residential",
"desc": "residential manufacture",
"parent": [
"rel-manufacture"
]
},
{
"key": "mumbai",
"desc": "mumbai location",
"parent": [
"rel-manufacture-mumbai"
]
}
]
}
MAPPING:::
%dw 2.0
output application/json
var A=payload map ((item, index) ->{
"key":item.business.ID,
"desc":item.business.desc
} )
var B=payload map ((item, index) ->{
"key":item.business.industry.ID,
"desc":item.business.industry.desc,
"parent":[item.business.ID]
} )
var C=payload map ((item, index) ->{
"key":item.business.industry.Businessline.ID,
"desc":item.business.industry.Businessline.desc,
"parent": [(item.business.ID)++"-"++(item.business.industry.ID)]
} )
var D=payload map ((item, index) ->{
"key":item.business.industry.Businessline.facility.ID,
"desc":item.business.industry.Businessline.facility.desc,
"parent": [(item.business.ID) ++"-"++ (item.business.industry.ID) ++"-"++
(item.business.industry.Businessline.facility.ID)]
} )

---
//{"asset":[A+B+C+D] reduce($++$$)}
{"asset":A ++ B ++ C ++ D}

42)INPUT:::

{
"key":"hellow world ",
"key1":"satish reddy",
"key2":"nemalidinne satish"
}
OUTPUT::::
{
"key": "hellow world",
"key1": "satish reddy",
"key2": "nemalidinne satish"
}
MAPPING::::
%dw 2.0
output application/json
import * from dw::core::Strings
fun removeSpace(StartData)=if(StartData[-1]==" ")removeSpace(StartData[0 to-2]) else
StartData
---
payload mapObject ((value, key, index) ->{
(key):removeSpace(value)
})
-----------------OR-----------------
%dw 2.0
output application/json
---
payload mapObject ((value, key, index) ->(key):value replace " " with "" )

43)
INPUT:::
{
"order": {
"place": {
"name": {
"firstName": "sachin",
"lastname": "tendulcurr",
"asisselm": {
"asile": "IT",
"asile": "Batsman",
"asile": "India"
}
}
}
},
"order": {
"place": {
"name": {
"firstName": "mahi",
"lastname": "sing",
"asisselm": {
"asile": "dhoni",
"asile": "Batsman",
"asile": "jarkand"
}
}
}
}
}
OUTPUT:::
[
{
"asisslem": "IT",
"Lastname": "tendulcurr"
},
{
"asisslem": "Batsman",
"Lastname": "tendulcurr"
},
{
"asisslem": "India",
"Lastname": "tendulcurr"
},
{
"lastname": "sing",
"asisslem": "dhoni"
},
{
"lastname": "sing",
"asisslem": "Batsman"
},
{
"lastname": "sing",
"asisslem": "jarkand"
}
]

MAPPING::
%dw 2.0
output application/json
var A=([payload] map ((item, index) ->item.order.place.name.asisselm pluck ((value, key,
index) ->{
"asisslem":value,
"Lastname":item....lastname[0]
} )))[0]
var B=flatten([payload[1]] map ((item, index) ->item.place.name.asisselm pluck ((value, key,
index) ->{
"lastname":item.place.name.lastname,
"asisslem":value
} ) ))
---
flatten(A+B)

.
------------------------------------------ Connectors -----------------------------------
----------------------
--------------------------------------------------------------------------------------------
----------------------

FORECH SCOPE::
Forech is like loope which runs Sequencelly (one by one)

You might also like