'How to declare a local variable in mule3
I am doing a data transformation in Mule 3. I am updating an existing code where a lot of variables are declared inside the DataWeave 1.0
I want to add a field called "type__c" inside a declared variable.
my input payload is as below
{
"billofPlaning": {
"billcollection": {
"itemDetail": [
{
"comm": [
{
"commodity": {
"itemSequence": 1,
"equipmentPrefix": "ABCD",
"equipmentNumber": "1234"
}
},
{
"commodity": {
"itemSequence": 2,
"equipmentPrefix": "DEFG",
"equipmentNumber": "5678"
}
}
]
}
]
},
"equip": [
{
"equipment": {
"prefix": "ABCD",
"number": "1234",
"type": 2345
}
},
{
"equipment": {
"prefix": "HIJ",
"number": "7890",
"type": 234567
}
}
]
}
}
My existing DataWeave 1.0 script is this:
%dw 1.0
%output application/java
%var inputData=payload
%var payBill= inputData.billofPlaning.billcollection.itemDetail default [] map (billcode,indexOfbillcode) -> {
billcode: {
"field1": "",
"type__c": ""
}
---
paybill
I want to reuse the below DataWeave 2.0 code in above DataWeave 1.0 code for the field "type__c".
%dw 2.0
output application/json
var test= ((payload.billofPlaning.equip) filter (($.equipment.prefix == payload.billofPlaning.billcollection.itemDetail.comm[0].commodity.equipmentPrefix[0])
and ($.equipment.number == payload.billofPlaning.billcollection.itemDetail.comm[0].commodity.equipmentNumber[0])))
---
"type__c": test.equipment."type"[0]
Can we do it in some better way using DataWeave 1.0 (basically using any local variable or something inside the payBill variable that we declared in DataWeave 1.0)?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
