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

如何自定义Graph API获取SharePoint多选PersonOrGroup列的LookupValue

解决Microsoft Graph API获取多选人员字段LookupValue的问题

需求说明

调用https://graph.microsoft.com/v1.0/sites/接口获取SharePoint列表数据时,Analyst字段为多选人员/组类型,当前返回的是包含LookupId、LookupValue、Email的数组结构,需要将该字段转换为仅返回LookupValue的字符串(多选时用逗号分隔),同时保留其他指定字段(如Test_x0020_Date)。

解决方案

方法1:API层面直接聚合为字符串(支持多选拼接)

利用OData的$apply操作符结合aggregate和collect,将多选的LookupValue聚合为数组,若需要直接得到逗号分隔的字符串,可搭配$compute和concat函数实现:

GET https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items?$top=5000&$apply=expand(fields($select=Test_x0020_Date;$aggregate(Analyst/LookupValue with collect as AnalystValues);$compute=concat(AnalystValues, ', ') as Analyst))&$select=fields

返回结果示例:

{
  "fields": {
    "Test_x0020_Date": "2022-06-08T05:00:00Z",
    "Analyst": "ABC, DEF"
  }
}

方法2:仅返回LookupValue数组(客户端自行处理)

若无需API直接拼接字符串,可通过$expand指定仅返回Analyst字段的LookupValue,减少冗余数据返回:

GET https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items?$top=5000&expand=fields($select=Test_x0020_Date;$expand=Analyst($select=LookupValue))&$select=fields

返回结果示例:

{
  "fields": {
    "Test_x0020_Date": "2022-06-08T05:00:00Z",
    "Analyst": [
      {"LookupValue": "ABC"},
      {"LookupValue": "DEF"}
    ]
  }
}

后续可在客户端提取数组中的LookupValue并拼接为逗号分隔的字符串。

注意事项

  • 替换请求URL中的{site-id}和{list-id}为实际的站点ID与列表ID;
  • 确保调用API的账号拥有对应SharePoint列表的读取权限;
  • $apply操作在Graph API v1.0版本中已支持,无需切换到beta版本。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 13:23:09