如何在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
相关产品推荐
相关产品推荐

