【问题标题】:Expanding fields not working fully on SharePoint Lists扩展字段无法在 SharePoint 列表上完全运行
【发布时间】:2018-05-01 03:13:04
【问题描述】:

我正在关注Get metadata for a list 的文档。

使用 PowerShell 或图形资源管理器进行查询无法完全展开 SharePoint 列表中项目的字段。

这方面的一个示例是名为 Responsible 的查找字段,它在 Azure Active Directory 中查找用户(或在 SharePoint 术语中,该列是 Person or Group 列,仅限于人员)。

一旦通过 GUI 选择,它就会填充一个显示名称(尽管我希望在后端存储更明确的信息,例如 UPN)。

使用表单查询 Graph API 时:

$Uri = "https://graph.microsoft.com/v1.0/sites/$($SPSite.id)/lists/$($ServiceList.id)/items?expand=fields"
$Data = Invoke-RestMethod -Headers @{Authorization = "Bearer $accesstoken"} -Uri $Uri -Method Get -ErrorAction Stop

我们得到这样的东西:

@odata.etag               : "REMOVED"
Title                     : Storage Platform
Description               : Central storage platform
ResponsibleLookupId       : 14
Responsible2LookupId      : 13
AccountableLookupId       : 3
Features                  : NFS
AudienceLookupId          : 92
RequestProcess            : {@{LookupId=1; LookupValue=Service Desk}}
Support                   : {@{LookupId=1; LookupValue=Service Desk}}
AvailabilityLookupId      : 1
DependsOn                 : {}
O365GroupLookupId         : 87
LifecycleStageLookupId    : 2
ConsultLookupId           : 88
id                        : 1
ContentType               : Item
Modified                  : 2017-11-17T10:47:07Z
Created                   : 2017-11-17T10:47:07Z
_UIVersionString          : 1.0
Attachments               : False
Edit                      : 
LinkTitleNoMenu           : Storage Platform
LinkTitle                 : Storage Platform
ItemChildCount            : 0
FolderChildCount          : 0
_ComplianceFlags          : 
_ComplianceTag            : 
_ComplianceTagWrittenTime : 
_ComplianceTagUserId      : 

您可以看到字段ResponsibleLookupId 只给出了14 的值,这没有用。其他字段链接到 Office 365 组,但再次返回值。因此,不可能将任何此类数据链接到用户/组,并且价值非常有限,除非通过门户网站查看。

我们如何扩展这些数据?它会在以后由 API 调用提供,还是我们必须执行进一步的查找?

【问题讨论】:

    标签: microsoft-graph-api sharepoint-online


    【解决方案1】:

    默认情况下,Microsoft Graph 将为查找字段返回 LookupId。您可以通过在 $select 参数中专门请求该字段来要求它提供实际值。

    使用以下查询将返回 displayName 而不是 LookupIdResponsible

    ...items?expand=fields($select=Responsible)
    

    您可以在FieldValueSet 的文档中了解其工作原理。

    至于返回userPrincipalName,目前您无法控制返回哪个值(LookupIddisplayName)。我建议访问UserVoice 并添加您的建议。

    【讨论】:

    • 谢谢 - 这行得通。我天真地假设 expand=fields 应该扩展所有字段,并且在末尾添加 ($select=) 只会优化该列表(就像在 PowerShell 中通过管道连接到 Select-Object 会做的那样)。我们可以在字段中强制选择/存储(?)电子邮件而不是显示名称,这更独特/可用。然而,对 12 个字段的最大查找感到遗憾。我将前往 UserVoice。
    • 我同意,电子邮件地址是更好的选择,但不幸的是人们并不总是可以控制默认值。如果您可以要求 ResponsibleExpanded 并获得完整的对象,而不仅仅是一个或另一个,那就太好了。至于 12,当我第一次开始使用它时,我也有同样的反应。在实践中,我发现我很少遇到限制,因为 12 个字段一次从一个集合中浮出水面。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-14
    • 2017-10-09
    • 1970-01-01
    • 2016-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多