Logic Apps中JSON数组与响应问题:CostsCalculation数组错误重复求助
解决Logic Apps中CostsCalculation重复数据的问题
问题根源
当前流程未针对每个服务的成本查询结果做空值判断,导致无成本数据时复用了之前循环的非空结果,而非设置为空数组。
调整方案
为成本查询结果添加空值判断
在查询当前服务的成本费率后,立即通过表达式判断结果是否为空。在构建每个服务的报价对象时,动态赋值CostsCalculation:- 使用
if(empty(body('查询成本费率')), [], body('查询成本费率'))表达式,当成本查询返回空时,设置为空数组;否则使用查询到的费率数据。
- 使用
重构对象构建逻辑
不要直接追加数组元素,改为为每个服务单独构建完整的报价对象,再将对象加入最终数组:- 遍历活跃服务,获取当前服务的销售费率并暂存
- 查询当前服务对应的成本费率
- 通过Compose步骤创建单个服务的报价对象,示例表达式:
{ "ChargeCode": @items('遍历服务')?['ChargeCode'], "ChargeDescription": "", "ChargesCalculation": @body('获取销售费率'), "CostsCalculation": @if(empty(body('查询成本费率')), [], body('查询成本费率')), "Currency": "USD" } - 将Compose的输出追加到最终的报价数组中
调整后预期输出
[ { "ChargeCode": "Carge2", "ChargeDescription": "", "ChargesCalculation": [ { "base": null, "break": null, "calculationType": "COS", "currency": "GBP", "max": null, "min": null, "rate": 1000 } ], "CostsCalculation": [ { "base": null, "break": null, "calculationType": "CTN", "currency": "USD", "max": null, "min": null, "rate": 27000 } ], "Currency": "USD" }, { "ChargeCode": "Charge1", "ChargeDescription": "", "ChargesCalculation": [ { "base": null, "break": null, "calculationType": "FLT", "currency": "GBP", "max": null, "min": null, "rate": 50 } ], "CostsCalculation": [], "Currency": "USD" } ]
内容的提问来源于stack exchange,提问作者Chris Pye
相关产品推荐
相关产品推荐

