问题描述
在将列表项上传到列表后,我正在尝试将值添加到列表项的自定义列中.我可以将项目放入列表中,并且可以查询列表并取回项目的数据,但是当我尝试为额外字段添加数据时,我得到以下 Microsoft.SharePoint.Client.InvalidClientQueryException代码>错误:
I'm trying to add values to a custom column on a list item after uploading the list item to the list. I can get the item into the list, and I can query the list and get back the item's data, but when I try to add the data for the extra field I get the following Microsoft.SharePoint.Client.InvalidClientQueryException
error:
找到了没有类型名称的值,并且没有可用的预期类型.指定模型时,有效负载中的每个值都必须具有一个类型,该类型可以是在有效负载中指定,由调用者显式指定或从父值隐式推断.
A value without a type name was found and no expected type is available. When the model is specified, each value in the payload must have a type which can be either specified in the payload, explicitly by the caller or implicitly inferred from the parent value.
我不确定错误消息所指的值或模型.这是我的代码:
I'm not sure what value or model the error message is referring to. This is my code:
var item = await graphClient
.Drives[driveId]
.Root.ItemWithPath(fileName)
.ListItem.Request()
.Select("WebURL,Fields,SharepointIds")
.Expand("Fields")
.GetAsync();
var fieldVals = await graphClient
.Sites[SPUrl + ":"]
.Sites[SpPath + ":"]
.Lists[libId]
.Items[item.SharepointIds.ListItemId]
.Fields
.Request()
.GetAsync();
fieldVals.AdditionalData.Add("Phase",
JsonConvert.SerializeObject(tags));
await graphClient
.Drives[driveId]
.Root
.ItemWithPath(fileName)
.ListItem
.Fields
.Request()
.UpdateAsync(fieldVals);
最初,当我在做 fieldVals.AdditionalData.Add()
时,我有Phase"和一个 List(string),这导致了关于未设置 OData 字段类型的错误,但我没有t 在说明预期 OData 字段值的文档中的任何地方都可以找到.我尝试将其设置为 microsoft.graph.fieldValueSet
但这不起作用.
Originally when I was doing fieldVals.AdditionalData.Add()
I had "Phase" and a List(string) and that caused an error about the OData field type not being set but I haven't found anywhere in the documentation that says what expected OData field values are. I tried setting it to microsoft.graph.fieldValueSet
but that didn't work.
我正在尝试更新允许多个选项作为复选框的选择列.
I'm trying to update a Choice column that allows multiple choices as checkboxes.
推荐答案
对于多选字段类型,确实,odata.type
注解的存在就是mandatory 在请求负载中,这里是一个如何指定它的示例:
For multi-choice field type, indeed, the presence of odata.type
annotation is mandatory in request payload, here is an example how to specify it:
PATCH https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items/{item-id}/
{
"fields": {
"<ChoiceFieldName>@odata.type": "Collection(Edm.String)",
"<ChoiceFieldName>":["<val1>","<val2>"]
}
}
在哪里
ChoiceFieldName
- 选择字段名称val1
,val2
- 字段值
ChoiceFieldName
- choice field nameval1
,val2
- field values
示例
假设一个 List 包含一个名为 Categories
的选择字段,那么下面的示例演示如何通过 msgraph-sdk-dotnet
:
Assuming a List contains a choice field named Categories
, then the following example demonstrates how to update list item via msgraph-sdk-dotnet
:
var choiceVals = new []{ "Cat1", "Cat2"};
await graphClient.Sites[siteId].Lists[listId].Items[itemId].Request().UpdateAsync(new ListItem()
{
Fields = new FieldValueSet
{
AdditionalData = new Dictionary<string, object>
{
{ "Categories@odata.type", "Collection(Edm.String)" },
{ "Categories", choiceVals }
}
}
});
参考文献
- 更新列表中的项目
- 实体数据模型:原始数据类型
这篇关于.NET Graph SDK 更新 Sharepoint 在线列表项值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!