Mule 4 中 dataweave 代码的条件逻辑

问题描述 投票:0回答:1

我需要有关 dataweave 代码的帮助。我的要求是根据以下标准在响应中添加状态字段。

var manditory_field =“D6V_Cod,D6V,DYR_Cod,DYR”

如果请求中的任何 manditory_field 为空,则状态值将为“Certified-Retry”。如果所有 manditory_field 参数值均可用,则状态值将为“已认证”。

注意:manditory_field 值是动态的。稍后可以添加其他字段。

输入:

        {
        "vin": "1234",
        "D6H": null,
        "D6H_Cod": null,
        "D6K": null,
        "D6K_Cod": null,
        "D6V": null,
        "D6V_Cod": null,
        "DCP": null,
        "DCP_Cod": null,
        "DI2": null,
        "DI2_Cod": null,
        "DJY": null,
        "DJY_Cod": null,
        "DXD": "04",
        "DXD_Cod": "CD",
        "DYD": null,
        "DYD_Cod": null,
        "DYR": null,
        "DYR_Cod": null,
        "DRC": null,
        "DRC_Cod": null,
        "DO9": null,
        "DO9_Cod": null,
        }

预期结果:

        {
        "vin": "1234",
        "D6H": null,
        "D6H_Cod": null,
        "D6K": null,
        "D6K_Cod": null,
        "D6V": null,
        "D6V_Cod": null,
        "DCP": null,
        "DCP_Cod": null,
        "DI2": null,
        "DI2_Cod": null,
        "DJY": null,
        "DJY_Cod": null,
        "DXD": "04",
        "DXD_Cod": "CD",
        "DYD": null,
        "DYD_Cod": null,
        "DYR": null,
        "DYR_Cod": null,
        "DRC": null,
        "DRC_Cod": null,
        "DO9": null,
        "DO9_Cod": null,
        "status": "Certified-Retry"
        }  
mule dataweave mulesoft mule-studio mule4
1个回答
0
投票

some
可用于确定是否有任何键属于字段列表

%dw 2.0
import * from dw::core::Arrays
output application/json
var mandatory_fields = ["D6V_Cod1","D6V","DYR_Cod","DYR"]
---
payload ++ (
    if (keysOf (payload) some ( mandatory_fields contains ($ as String))) 
    {
        status: "Certified-Retry"
    } else {
        status: "Certified"
    }
)
© www.soinside.com 2019 - 2024. All rights reserved.