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

Power Automate Filter Array输出对象类型致循环报错求助

Power Automate入职提醒流循环报错排查

预期功能

  • 检查SharePoint列表中今日需接收提醒邮件的员工
  • 确定需发送的提醒类型
  • 提取员工名用于邮件主题与正文
  • 根据员工入职日期按时间间隔设置下一次提醒日期
  • 重复执行直至员工退出提醒序列

SharePoint列表字段

  • User Name(邮箱)
  • First name
  • Last name
  • Email address
  • Employee Communication Language
  • Manager Email
  • Manager communication language
  • Start date
  • Next reminder date
  • Reminder status
  • Birthday
  • Email Opt in
  • Years of service

流步骤与报错情况

  1. Recurrence:测试时每10分钟运行一次,实际每日运行一次
  2. Get items:引用SharePoint列表,筛选查询:
    NextReminderDate ge '@{formatDateTime(utcNow(), 'yyyy-MM-dd')}T00:00:00Z' and NextReminderDate lt '@{formatDateTime(addDays(utcNow(), 1), 'yyyy-MM-dd')}T00:00:00Z'
    
  3. Filter array:高级模式,From为@outputs('Get_items')?['body/value'],筛选条件:
    @and(
    greaterOrEquals(
    formatDateTime(convertTimeZone(item()?['NextReminderDate'], 'UTC', 'Eastern Standard Time'), 'yyyy-MM-ddTHH:mm'),
    formatDateTime(convertTimeZone(addMinutes(utcNow(), -1), 'UTC', 'Eastern Standard Time'), 'yyyy-MM-ddTHH:mm')
    ),
    lessOrEquals(
    formatDateTime(convertTimeZone(item()?['NextReminderDate'], 'UTC', 'Eastern Standard Time'), 'yyyy-MM-ddTHH:mm'),
    formatDateTime(convertTimeZone(addMinutes(utcNow(), 1), 'UTC', 'Eastern Standard Time'), 'yyyy-MM-ddTHH:mm')
    )
    
  4. Compose:调试用,输入为@{outputs('Filter_array')
  5. Apply to each(Apply to Each 5):引用@{body('Filter_array')?['body']},其内部嵌套的Apply to each引用@{items('Apply_to_each_5')},触发报错:
    The execution of template action 'Apply_to_each' failed: the result of the evaluation of 'foreach' expression '@items('Apply_to_each_5')' is of type 'Object'. The result must be a valid array.
    
    嵌套循环内计划通过Switch(基于@{items('First_Day_Email')?['ReminderStatus/Value']})和Condition判断语言,发送对应英文/法语邮件,并更新SharePoint列表的Next Reminder Date与Reminder Status字段,需处理4种提醒类型。

调试输出(脱敏后)

{
    "body": [
        {
            "@odata.etag": "\"321\"",
            "ItemInternalId": "26",
            "ID": 26,
            "UserName": "firstname.lastname@company.com",
            "FirstName": "John",
            "LastName": "Doe",
            "EmailAddress": "firstname.lastname@company.com",
            "EmployeeCommunicationLanguage": {
                "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
                "Id": 0,
                "Value": "English"
            },
            "EmployeeCommunicationLanguage#Id": 0,
            "ManagerEmail": "firstname.lastname@company.com",
            "ManagerCommunicationLanguage": {
                "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
                "Id": 0,
                "Value": "English"
            },
            "ManagerCommunicationLanguage#Id": 0,
            "StartDate": "2024-11-21T14:30:00Z",
            "NextReminderDate": "2024-11-21T14:30:00Z",
            "ReminderStatus": {
                "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
                "Id": 0,
                "Value": "First Day"
            },
            "ReminderStatus#Id": 0,
            "Birthday": "2024-10-10",
            "EmailOptIn": {
                "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
                "Id": 0,
                "Value": "Yes"
            },
            "EmailOptIn#Id": 0,
            "YearsOfService": 0,
            "Modified": "2024-11-21T14:26:52Z",
            "Created": "2024-04-22T02:23:07Z",
            "Author": {
                "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
                "Claims": "i:0#.f|membership|firstname.lastname@company.com",
                "DisplayName": "Johnny Doe",
                "Email": "firstname.lastname@company.com",
                "Picture": "https://company365.sharepoint.com/sites/Marketing/_layouts/15/UserPhoto.aspx?Size=L&AccountName=firstname.lastname@company.com",
                "Department": "Marketing",
                "JobTitle": "Marketing Manager"
            },
            "Author#Claims": "i:0#.f|membership|firstname.lastname@company.com",
            "Editor": {
                "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
                "Claims": "i:0#.f|membership|firstname.lastname@company.com",
                "DisplayName": "Johnny Doe",
                "Email": "firstname.lastname@company.com",
                "Picture": "https://company365.sharepoint.com/sites/Marketing/_layouts/15/UserPhoto.aspx?Size=L&AccountName=firstname.lastname@company.com",
                "Department": "Marketing",
                "JobTitle": "Marketing Manager"
            },
            "Editor#Claims": "i:0#.f|membership|firstname.lastname@company.com",
            "{Identifier}": "Lists%252fTest%2bHR%2bMailing%2bDB%252f26_.000",
            "{IsFolder}": false,
            "{Thumbnail}": {
                "Large": null,
                "Medium": null,
                "Small": null
            },
            "{Link}": "https://company365.sharepoint.com/sites/Marketing/_layouts/15/listform.aspx?PageType=4&ListId=f005fd8d%2D3901%2D474a%2Dbe7a%2D3cdbd4fbd149&ID=26&ContentTypeID=0x0100EB5F7FD3E55DCC4CA6D5F13E31528A90001D414B65A006B34A9D620F2505659474",
            "{Name}": "",
            "{FilenameWithExtension}": "",
            "{Path}": "Lists/Test HR Mailing DB/",
            "{FullPath}": "Lists/Test HR Mailing DB/26_.000",
            "{HasAttachments}": false,
            "{VersionNumber}": "321.0"
        }
    ]
}

问题分析与修复方案

错误原因

  • Filter array的输出结构为{"body": [员工对象数组]},body('Filter_array')直接指向该数组
  • 第一个Apply to Each 5遍历的是数组中的单个员工对象(类型为Object)
  • 嵌套的Apply to each试图遍历单个员工对象,但Apply to each仅支持处理数组,因此触发类型错误

修复步骤

  1. 删除嵌套的Apply to each循环
  2. 在Apply to Each 5内部直接使用items('Apply_to_each_5')访问当前员工的字段:
    • Switch条件改为@{items('Apply_to_each_5')?['ReminderStatus/Value']}
    • 邮件内容、列表更新操作均基于items('Apply_to_each_5')获取数据
  3. 确认Apply to Each 5的数据源为body('Filter_array')(或body('Filter_array')?['body'],两者等价)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 01:02:04