You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Logic App中For_each表达式返回NULL的异常排查

Azure Logic App For_each 表达式返回Null问题排查

我正在获取Azure DevOps查询结果,用来判断User Story过去一天内是否未被修改(changedate),参照相关文档构建Logic App,场景需求类似。

尽管查询返回了至少1条有效User Story响应,但For_each表达式抛出错误:

ExpressionEvaluationFailed. The execution of template action 'For_each' failed: the result of the evaluation of 'foreach' expression '@body('Parse_JSON')?['body']?['value']' is of type 'Null'. The result must be a valid array.

明明有User Story返回,为何表达式结果为Null?


获取查询结果(Get query results)

输出(OUTPUTS):

[
  {
    "System.Id": 12345,
    "System.WorkItemType": "User Story",
    "System.State": "New",
    "System.Title": "Experiment"
  }
]

解析JSON(Parse JSON)

输入(Inputs)- 内容(Content):

{
  "value": [
    {
      "System.Id": 12345,
      "System.WorkItemType": "User Story",
      "System.State": "New",
      "System.Title": "Experiment"
    }
  ],
  "@odata.nextLink": null
}

Schema:

{
  "type": "object",
  "properties": {
    "body": {
      "type": "object",
      "properties": {
        "value": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "System.AssignedTo": {
                "type": "string"
              },
              "System.Id": {
                "type": "integer"
              },
              "System.State": {
                "type": "string"
              },
              "System.Tags": {
                "type": "string"
              },
              "System.Title": {
                "type": "string"
              },
              "System.WorkItemType": {
                "type": "string"
              }
            },
            "required": [
              "System.Id",
              "System.WorkItemType",
              "System.State",
              "System.AssignedTo",
              "System.Title"
            ]
          }
        },
        "@odata.nextLink": {}
      }
    },
    "headers": {
      "type": "object",
      "properties": {
        "Cache-Control": {
          "type": "string"
        },
        "Content-Length": {
          "type": "string"
        },
        "Content-Type": {
          "type": "string"
        },
        "Date": {
          "type": "string"
        },
        "Expires": {
          "type": "string"
        },
        "Pragma": {
          "type": "string"
        },
        "Set-Cookie": {
          "type": "string"
        },
        "Strict-Transport-Security": {
          "type": "string"
        },
        "Timing-Allow-Origin": {
          "type": "string"
        },
        "Transfer-Encoding": {
          "type": "string"
        },
        "Vary": {
          "type": "string"
        },
        "X-Content-Type-Options": {
          "type": "string"
        },
        "X-Frame-Options": {
          "type": "string"
        },
        "x-ms-apihub-cached-response": {
          "type": "string"
        },
        "x-ms-apihub-obo": {
          "type": "string"
        },
        "x-ms-request-id": {
          "type": "string"
        }
      }
    },
    "statusCode": {
      "type": "integer"
    }
  }
}

输出(Outputs):

{
  "value": [
    {
      "System.Id": 12345,
      "System.WorkItemType": "User Story",
      "System.State": "New",
      "System.Title": "Experiment"
    }
  ],
  "@odata.nextLink": null
}

问题原因

Parse JSON组件的Schema定义与实际输入/输出结构完全不匹配:

  • Schema里定义的外层结构包含body、headers、statusCode,但实际Parse JSON的输入和输出直接是value和@odata.nextLink,不存在外层的body节点。
  • For_each表达式@body('Parse_JSON')?['body']?['value']试图访问不存在的body节点下的value,自然返回Null。

修复步骤

  1. 修正Parse JSON的Schema:删除冗余的外层节点,匹配实际输入结构:
{
  "type": "object",
  "properties": {
    "value": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "System.Id": {
            "type": "integer"
          },
          "System.WorkItemType": {
            "type": "string"
          },
          "System.State": {
            "type": "string"
          },
          "System.Title": {
            "type": "string"
          },
          "System.AssignedTo": {
            "type": "string"
          },
          "System.Tags": {
            "type": "string"
          }
        },
        "required": [
          "System.Id",
          "System.WorkItemType",
          "System.State",
          "System.Title"
        ]
      }
    },
    "@odata.nextLink": {
      "type": ["null", "string"]
    }
  }
}

(注:如果部分User Story缺少System.AssignedTo或System.Tags字段,可将其从required数组中移除,避免解析失败)

  1. 修正For_each的表达式:直接访问Parse JSON输出中的value数组:
@body('Parse_JSON')?['value']
  1. 重新运行Logic App,For_each即可正常遍历返回的User Story列表。

内容的提问来源于stack exchange,提问作者Cataster

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 08:20:53