我正在尝试转换 xml 请求,但在映射 ID 参数时遇到问题。
对于 account_work,我必须映射 id,其中类型为 Revenue_category_id。
对于 ledger_work,我必须映射 id,其中类型为 Ledger_category_id。
请帮助在 dwl 代码中获得正确的过滤器逻辑。
dwl:
%dw 2.0
output application/json
---
payload.Get_Mapping_Tables_Response.Response_Data.Mapping_Table.Mapping_Table_Data.*Rule_Table_Data map {
"account_work": $.Accounting_working.ID, // need to add filer logic to get Revenue_category_id
"ledger_work": $.Ledger_working.ID // need to add filer logic to get Ledger_category_id
}
要求:
<wd:Get_Mapping_Tables_Response
xmlns:wd="urn:com.workday/bsve" wd:version="v40.0">
<wd:Response_Data>
<wd:Mapping_Table>
<wd:Mapping_Table_Data>
<wd:ID>AC_Account_Map</wd:ID>
<wd:Rule_Table_Data>
<wd:Accounting_working>
<wd:ID wd:type="WID">1234</wd:ID>
<wd:ID wd:type="Revenue_category_id">RC_1</wd:ID>
</wd:Accounting_working>
<wd:Ledger_working>
<wd:ID wd:type="WID">12345</wd:ID>
<wd:ID wd:type="Ledger_category_id">LC_1</wd:ID>
</wd:Ledger_working>
</wd:Rule_Table_Data>
<wd:Rule_Table_Data>
<wd:Accounting_working>
<wd:ID wd:type="WID">12346</wd:ID>
<wd:ID wd:type="Revenue_category_id">RC_2</wd:ID>
</wd:Accounting_working>
<wd:Ledger_working>
<wd:ID wd:type="WID">12347</wd:ID>
<wd:ID wd:type="Ledger_category_id1">LC_2</wd:ID>
</wd:Ledger_working>
</wd:Rule_Table_Data>
</wd:Mapping_Table_Data>
</wd:Mapping_Table>
</wd:Response_Data>
</wd:Get_Mapping_Tables_Response>
预期回应:
[
{
"account_work": "RC_1",
"ledger_work": "LC_1"
},
{
"account_work": "RC_2",
"ledger_work": ""
}
]
使用 filterObject() 并以键的
type
属性为条件。非当前值返回 null,因此我添加了默认的空字符串以匹配预期的输出。
%dw 2.0
output application/json
---
payload.Get_Mapping_Tables_Response.Response_Data.Mapping_Table.Mapping_Table_Data.*Rule_Table_Data map {
"account_work": ($.Accounting_working filterObject ((value, key, index) -> key.@`type` == "Revenue_category_id")).ID default "",
"ledger_work": ($.Ledger_working filterObject ((value, key, index) -> key.@`type` == "Ledger_category_id")).ID default ""
}