PowerApps Patch带Lookup字段的SharePoint列表报错,如何解决?
问题描述
我尝试用PowerApps的Patch函数更新名为City的SharePoint列表,该列表里有一个指向Country列表的Lookup列Country,这个Lookup列还关联了Language和Title附加字段,但执行时出现报错:
- 版本1报错:
"The field 'Country_x003a__x0020_Title' is required."
- 版本2报错:
"Error in 'City': Invalid data was used to update the list item. The field you are trying to update may be read-only."
列表结构
- Country列表:包含字段
Title、ID、Language - City列表:包含字段
Name、Citizen Count、指向Country的Lookup列Country、额外的LanguageLookup列
尝试过的代码
版本1
Patch( City; Defaults(City); { Country: { '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference"; Id: CurrentItem.ID; Value: CurrentItem.ID; 'Country_x003a__x0020_Title': CurrentItem.Title; // Correct internal name 'Country_x003a__x0020_Language': CurrentItem.Language // Correct internal name }; } )
版本2
Patch( City; Defaults(City); { Country: { '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference"; Id: CurrentItem.ID; Value: CurrentItem.ID; }; Country_x003a__x0020_Title: { '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference"; Id: CurrentItem.ID; Value: CurrentItem.ID; }; } )
补充细节
CountryLookup列要求必须填充Title字段- 已验证SharePoint字段内部名称和Patch中使用的一致
- 即使提供了
Country_x003a__x0020_Title和Country_x003a__x0020_Language的值,错误依然存在
解决方案
核心问题
SharePoint的Lookup附加字段是只读的,不能直接通过Patch写入,它们会自动从关联的Country列表中同步。你只需要正确设置Lookup列的Id和Value(这里的Value应该是Country列表中Lookup列设置的显示字段,通常是Title,而不是ID),附加字段会自动填充。
修正后的Patch代码
Patch( City; Defaults(City); { Country: { '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference"; Id: CurrentItem.ID; // 对应Country列表的ID Value: CurrentItem.Title // 这里必须是Country列表中Lookup列设置的显示字段,通常是Title } // 不需要手动设置Country_x003a__x0020_Title和Country_x003a__x0020_Language,会自动同步 } )
关键说明
- Value字段的正确性:Lookup列的
Value必须是你在SharePoint中配置Lookup列时选择的「显示字段」,如果你的Country Lookup列显示字段是Title,就填CurrentItem.Title,而不是CurrentItem.ID,这是版本1中可能的错误点。 - 附加字段无需手动写入:
Country_x003a__x0020_Title这类附加字段是SharePoint自动维护的,属于只读字段,手动写入会触发版本2的「只读字段」报错。 - 必填字段验证:只要正确设置了Lookup列的
Id和Value,SharePoint会自动同步附加字段,满足Title必填的要求,解决版本1的报错。
内容的提问来源于stack exchange,提问作者Rubick
相关产品推荐
相关产品推荐

