如何使用 Microsoft Graph API 更新 SharePoint 列表中人员或组列的值? [英] How do I update the value of Person or Group columns in SharePoint lists using the Microsoft Graph API?

查看:35
本文介绍了如何使用 Microsoft Graph API 更新 SharePoint 列表中人员或组列的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Microsoft Graph API(测试版)来更新 SharePoint ListItems.但是,我无法更改个人或组"列的值.该列具有允许多选"属性并接受个人和组.这是它作为 ListItem columnSet 的一部分的样子:

I am using the Microsoft Graph API (Beta) to update SharePoint ListItems. However, I am failing to change the value of a 'Person or Group' column. The column has the attribute 'Allow multiple selections' and accepts both persons and groups. This is how it looks like as part of the ListItem columnSet:

{ 
  "AssignedTo": [
    {
      "Email": "user@domain.com", 
      "LookupId": 123, 
      "LookupValue": "User Name"
    }
  ]
}

什么有效

更新个人或组"以外的列的值工作正常:如文档所述,我正在向 ListItem 的 columnSet 发送 PATCH 请求.请求标头包含内容类型application/json",请求正文包含列名称及其(新)值的 JSON 编码字典:

What works

Updating the value of columns other than 'Person or Group' is working fine: As documented, I am sending a PATCH request to the ListItem's columnSet. The request header contains the content type 'application/json' and the request body contains a JSON-encoded dictionary of column names and their (new) values:

{
  "RegularColumn": "new value"
}

什么不起作用

我已经尝试了很多使用用户的 ID、电子邮件和/或姓名,但我得到的只是这个错误:请求格式错误或不正确."

What does NOT work

I have experimented quite a bit with using the user's id, email and/or name, but all I get is this error: 'The request is malformed or incorrect.'

如何更新个人或组"列的值?示例 JSON 请求正文是什么样的?

感谢您的建议!

推荐答案

我一直在寻找相同问题的解决方案,但在 StackOverflow 或 Web 上都没有找到任何解决方案.感谢 Vadim Gremyachev 的帖子 (在此处查看有关查找"类型字段的相关问题),我能够通过 Graph Api 使用激活的设置allowMultipleSelection"成功更新personOrGroup"类型的字段.您可以通过将字段名称与 LookupId 组合并将 LookupId 作为值传递来更新单值personOrGroup"字段:

I have been looking for a solution to the same issue for quite a while and did not find any solutions on StackOverflow or the web. Thanks to the post from Vadim Gremyachev (See the related question regarding fields of type 'lookup' here), I was able to successfully update a field of type 'personOrGroup' with the activated setting 'allowMultipleSelection' via the Graph Api. You can update single value 'personOrGroup' fields, by combining the field name with LookupId and passing the LookupId as the value:

{
   "AssignedToLookupId":"123"
}

如果你想更新一个多值的'personOrGroup'字段,你需要先指定数据类型并将ids作为数组传递:

If you want to update a multi value 'personOrGroup' fields, you need to specify the data type first and pass the ids as an array:

{
   "AssignedToLookupId@odata.type":"Collection(Edm.String)",
   "AssignedToLookupId":["123", "124"] 
}

这篇关于如何使用 Microsoft Graph API 更新 SharePoint 列表中人员或组列的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆