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

如何在Power Apps组合框中实现新建表单显当前用户、编辑表单显SharePoint值?

解决组合框在表单新建/非新建状态下的用户显示问题

问题根源

你原公式报错的核心原因是:Office365Users.MyProfile()返回的用户对象结构,和SharePoint用户列的记录结构不匹配,组合框要求DefaultSelectedItems的记录必须与自身数据源的结构完全一致,类型不匹配就会触发错误。

解决方案

根据组合框的数据源类型,选择对应的修正公式:

情况1:组合框数据源为Office365Users搜索结果

如果你的组合框数据源是Office365Users.SearchUser({searchTerm: ComboBox1.SearchText}),使用以下公式:

With(
    {currentUser: Office365Users.MyProfile()},
    If(
        EditForm1.Mode = FormMode.New,
        {
            DisplayName: currentUser.DisplayName,
            Email: currentUser.Mail,
            Claims: "i:0#.f|membership|" & Lower(currentUser.Mail),
            Department: currentUser.Department,
            JobTitle: currentUser.JobTitle,
            Picture: currentUser.Picture
        },
        ThisItem.SharepointColumn
    )
)

情况2:组合框数据源为SharePoint用户列选项

如果你的组合框数据源是Choices(你的列表名.SharepointColumn),使用以下公式:

With(
    {currentUser: Office365Users.MyProfile()},
    If(
        EditForm1.Mode = FormMode.New,
        {
            '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
            Claims: "i:0#.f|membership|" & Lower(currentUser.Mail),
            DisplayName: currentUser.DisplayName,
            Email: currentUser.Mail,
            JobTitle: "",
            Picture: ""
        },
        ThisItem.SharepointColumn
    )
)

关键说明

  • 使用With函数可以避免重复调用Office365Users.MyProfile(),减少API请求次数
  • 必须确保构造的记录包含组合框数据源要求的核心字段(比如Claims是SharePoint用户列的必填标识字段)
  • 非新建状态直接返回ThisItem.SharepointColumn即可,因为这本身就是符合结构的用户记录

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.26 06:03:25