Input JSON is
%dw 2.0
output application/json
---
[
{
"Master_Job__r": {
"Description_of_Loss__c": "This is Raja",
"Date_of_Loss__c": "2020-06-08",
"Id": null,
"type": "Master_Job__c"
},
"Amount__c": null,
"Job_Number__c": "C##-#7-00041",
"Property_ID__r": {
"Country__c": "United States",
"City__c": "Chennai",
"Zip__c": "77777",
"Address_Line_1__c": "null Testa St",
"Id": null,
"type": "Home",
"State__c": "CA",
"phone__C": "948-125-6666",
"Job_Number__C": "GSD-45613",
"Phone_Ext__C": "257452",
"TOL_Code__c": "EARTHQUAKE",
"TOL_desc__c": "",
"PolicyNum__c": "GSD-123654",
"COvapplyTo__c": "0",
"PolicyLim__c": "156",
"PolDeduc__c": "1562",
"Covname__c": "Rup",
"CovType__c": "4",
"id__c": "4586",
"Date_Taken__c": "2020-08-16",
"Email__c": "[email protected]",
},
"Email__C": "[email protected]",
"Account_Roles__r": [
{
"Multiple_Roles__c": "Primary/Bill-to;Caller",
"Id": null,
"type": "Account_Roles__c",
"Contact_ID__r": {
"Name": "Test QA"
}
},
{
"Multiple_Roles__c": "Project Site Contact",
"type": "Account_Roles__c",
"Contact_ID__r": {
"Name": "Test DB Con002"
}
}
],
"Id": null,
"Project_Manager_Email__c": null
}
]
Dataweave code in XML is
%dw 2.0
output application/xml
---
XACTDOC: {(payload map(object,index)->{
ADM:{
dateofloss @("Dateofloss":payload.Master_Job__r[0].Date_of_Loss__c as String,"dateReceived":payload.Property_ID__r[0].Date_Taken__c as String):""default""
},
TOLcode: {
"test": payload.Property_ID__r[0].TOL_Code__c as String,
"Desc": p('Typeofloss.EARTHQUAKE')
}
})}
Output XML Format is
<?xml version='1.0' encoding='UTF-8'?>
<XACTDOC>
</ADM><Coverage_Loss><PolicyNumber PolNum="GSD-123654" claimNumber="GSD-45613"/>
<TOLcode><test>EARTHQUAKE</test><Desc>Earthquake</Desc></TOLcode></XACTDOC>
And i have created and stored a Name value lookup in .YAML File like
Typeofloss:
EARTHQUAKE: "Earthquake"
FIRE: "Fire"
Flood: "Flood"
FREEZE: "Freeze"
VANDALISM: "Vandalism"
ENVIRONMENT: "Environmental Remediation"
STORM: "Hurrican/Tornado/Blizzard/Noreaster"
And now my requirement is if TOL_CODE "Test" field is "STORM" then i need "DESC" field as a "Hurrican/Tornado/Blizzard/Noreaster" as an Output. I will get Input TOL_CODE values dynamically. How can we get the lookup values in Dataweave expressions without entering manually. i tried with this logic but it is not working.
"test": payload.Property_ID__r[0].TOL_Code__c as String, "Desc": p('Typeofloss.'+payload.Property_ID__r[0].TOL_Code__c)
Use ++
to concat strings for the Desc field i.e.
"Desc": p('Typeofloss.' ++ payload.Property_ID__r[0].TOL_Code__c)
Reference: https://docs.mulesoft.com/mule-runtime/4.3/dw-core-functions-plusplus#plusplus2