需要帮助识别计划线数组对象并将数量字段设置为删除“”的数字。我需要一些关于如何访问 _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;
}
这是我的示例有效负载:
{
"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 - 与您正在使用的其他属性相同,但它包含对象数组作为值
因此,您必须迭代数组才能访问嵌套对象属性。