Need to help identify the scheduleline array object and set the quantity field to number removing the "". I need some pointers on how i can access the _PurchaseOrderScheduleLineTP.ScheduleLineOrderQuantity
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.json.*
def Message processData(Message message) {
def body = message.getBody(java.lang.String);
def object = new JsonSlurper().parseText(body)
object._PurchaseOrderItem.each{_PurchaseOrderItem->
_PurchaseOrderItem.NetPriceQuantity = _PurchaseOrderItem.NetPriceQuantity.toDouble().intValue()
_PurchaseOrderItem.NetAmount = _PurchaseOrderItem.NetAmount.toDouble()
_PurchaseOrderItem.GrossAmount = _PurchaseOrderItem.GrossAmount.toDouble()
_PurchaseOrderItem.OrderQuantity = _PurchaseOrderItem.OrderQuantity.toDouble()
_PurchaseOrderItem.NetPriceAmount = _PurchaseOrderItem.NetPriceAmount.toDouble()
}
object._PurchaseOrderItem.each{_PurchaseOrderItem->
_PurchaseOrderScheduleLineTP.each{_PurchaseOrderScheduleLineTP->
_PurchaseOrderScheduleLineTP.number =_PurchaseOrderScheduleLineTP.ScheduleLineOrderQuantity.toDouble().intValue()
}
}
//object._PurchaseOrderScheduleLineTP.each{_PurchaseOrderItem._PurchaseOrderScheduleLineTP->
//_PurchaseOrderScheduleLineTP.ScheduleLineOrderQuantity = _PurchaseOrderScheduleLineTP.ScheduleLineOrderQuantity.toDouble().intValue()
//}
message.setBody(JsonOutput.toJson(object));
return message;
}
Here's my sample payload:
{
"PurchaseOrderType": "NB",
"PurchaseOrderDate": "2024-05-14",
"Language": "EN",
"CompanyCode": "2024",
"PurchasingOrganization": "2024",
"PurchasingGroup": "001",
"Supplier": "1000000",
"DocumentCurrency": "USD",
"_PurchaseOrderItem": [
{
"PurchaseOrderItem": "10",
"PurchaseOrderCategory": "F",
"DocumentCurrency": "USD",
"MaterialGroup": "E002",
"PurchaseOrderItemText": "From CPI",
"ProductTypeCode": "1",
"CompanyCode": "2024",
"Plant": "2024",
"PurchaseOrderQuantityUnit": "EA",
"OrderPriceUnit": "EA",
"NetPriceQuantity": "1",
"PurchaseOrderItemCategory": "0",
"AccountAssignmentCategory": "P",
"NetAmount": "10",
"GrossAmount": "10",
"OrderQuantity": "10",
"NetPriceAmount": "1",
"_PurchaseOrderScheduleLineTP": [{
"ScheduleLineDeliveryDate": "2024-05-14",
"SchedLineStscDeliveryDate": "2024-05-14",
"ScheduleLineOrderQuantity": "10",
"PurchaseOrderQuantityUnit": "EA",
"Currency": "USD"
}],
"_PurOrdAccountAssignment": [{
"AccountAssignmentNumber": "1",
"OrderQuantityUnit": "EA",
"Quantity": "10",
"DocumentCurrency": "USD",
"CostCenter": "20240001",
"GLAccount": "42007000",
"Fund": "FUND1",
"CompanyCode": "2024",
"ChartOfAccounts": "XXOA",
"ControllingArea": "ABCD",
"ProfitCenter": "XXXX"
}]
}
]
}
_PurchaseOrderScheduleLineTP - the same property as others that you are working with, but it contains array of objects as value
so, you have to iterate the array to access nested objects properties.
object._PurchaseOrderItem.each{_PurchaseOrderItem->
_PurchaseOrderItem.NetPriceQuantity = _PurchaseOrderItem.NetPriceQuantity as Integer
...
_PurchaseOrderItem._PurchaseOrderScheduleLineTP.each{i->
i.ScheduleLineOrderQuantity = i.ScheduleLineOrderQuantity as Integer
}
}