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

Power Apps:如何批量Patch多人员列至SharePoint及集合?

解决Power Apps批量Patch多人员列到SharePoint的问题

问题核心

你的代码中Members字段的处理逻辑错误:使用Collect(colMem, ...)会不断往集合里累加数据,而非直接生成当前行需要的用户对象数组,同时没有正确引用Gallery行内的ComboBox控件,且用户信息构造时用了DisplayName而非更可靠的Email。

修正后的完整代码

ForAll(
    Filter(gal_NewBudget_4.AllItems, tog_NewBudget_isChanged_2.Value) As NewUnitRows,
    Patch(colAdminUnits, Defaults(colAdminUnits), {
        ID: NewUnitRows.ID,
        Title: NewUnitRows.txt_AdminUnits_Unit.Text,
        Department: NewUnitRows.txt_AdminUnits_Dept.Text,
        UnitHead: {
            '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
            Claims: "i:0#.f|membership|" & Lower(NewUnitRows.cmb_AdminUnits_UnitHead.Selected.Email),
            Department: "",
            DisplayName: NewUnitRows.cmb_AdminUnits_UnitHead.Selected.DisplayName,
            Email: NewUnitRows.cmb_AdminUnits_UnitHead.Selected.Email,
            JobTitle: "",
            Picture: ""
        },
        DepartmentHead: {
            '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
            Claims: "i:0#.f|membership|" & Lower(NewUnitRows.cmb_AdminUnits_DeptHead.Selected.Email),
            Department: "",
            DisplayName: NewUnitRows.cmb_AdminUnits_DeptHead.Selected.DisplayName,
            Email: NewUnitRows.cmb_AdminUnits_DeptHead.Selected.Email,
            JobTitle: "",
            Picture: ""
        },
        Members: ForAll(
            NewUnitRows.cmb_AdminUnits_PVInitiator.SelectedItems,
            {
                '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
                Claims: "i:0#.f|membership|" & Lower(ThisRecord.Email),
                Department: "",
                DisplayName: ThisRecord.DisplayName,
                Email: ThisRecord.Email,
                JobTitle: "",
                Picture: ""
            }
        )
    })
);

关键修改点

  • Members字段修正:移除Collect(colMem, ...),让ForAll直接返回构造好的用户对象数组,这样每一行的Members都会是当前ComboBox选中的人员列表,不会互相干扰。
  • 引用行内控件:将cmb_AdminUnits_PVInitiator改为NewUnitRows.cmb_AdminUnits_PVInitiator,确保循环时取的是当前Gallery行内的ComboBox,而非全局控件。
  • 用户信息准确性:将Claims和Email字段从DisplayName改为Email,并添加Lower()统一格式,避免因DisplayName重复导致的身份识别错误(SharePoint用户Claims依赖邮箱唯一性)。
  • 移除冗余集合操作:不需要额外的colMem集合,直接通过ForAll生成符合SharePoint多人员字段要求的对象数组即可。

额外注意事项

  • 确保SharePoint列表的Members字段是多人员类型,允许选择多个用户。
  • 测试时可以先在Power Apps中查看colAdminUnits集合的内容,确认Members字段是否正确生成了用户对象数组,再同步到SharePoint。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 20:56:28