SharePoint 列表项的 AddAsync 上无法识别字段 [英] Field Not Recognized on AddAsync of SharePoint List Item

查看:42
本文介绍了SharePoint 列表项的 AddAsync 上无法识别字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用基本日历/列表字段创建新列表项时,一切正常.但是,当我尝试使用非标准"字段(即我添加的字段)执行此操作时,出现字段无法识别"错误.

When I try to create a new list item with the basic calendar/list fields everything works perfectly. However, when I try to do so with a "non-standard" field i.e. a field I added, I am getting a "field not recognized" error.

该字段显然就在那里!是否需要通过某种特殊方式来填充这些自定义字段?

The field is clearly there! Is there some special way I need to populate these custom fields?

// get a specific list
ISiteListsCollectionPage list = await graphClient.Sites["root"].Lists.Request()
    .Filter($"DisplayName eq 'Outlook Integration'").GetAsync();

// create a dictionary of [calendar] list properties
Dictionary<string, object> props = new Dictionary<string, object>();

// populate properties, all of these work just fine
props.Add("Title", evt.Subject);
props.Add("Location", evt.Location?.DisplayName);
props.Add("EventDate", utcStart.ToString("yyyy-MM-ddTHH:mm:ssK"));
props.Add("EndDate", utcEnd.ToString("yyyy-MM-ddTHH:mm:ssK"));
props.Add("Description", Regex.Replace(evt.Body.Content, "<.*?>", String.Empty)); // remove HTML content

// populate custom properties
props.Add("ResourceID", evt.Id); // throws error: Field 'ResourceID' is not recognized

// create list item with our properties dictionary
var newItem = new ListItem
{
    Name = "My New Event",
    Fields = new FieldValueSet()
    {
        AdditionalData = props
    }
};

// call the service and get the result
var newListItem = await graphClient.Sites["root"].Lists[list[0].Id].Items.Request().AddAsync(newItem);

这是我列表中的完整字段列表:

This is the complete list of fields on my list:

在这里您可以看到显示名称是ResourceID",而 API 名称是O365EventId".但是,两者都会导致相同的错误,无法识别字段."

Here you can see the display name is "ResourceID" whereas the API name is "O365EventId." However, both result in the same error, "Field not recognized."

注意: ResourceID 是我添加的字段之一.如何通过 Graph API 设置此字段的值?

Note: ResourceID is one of the fields that I added. How can I set the value of this field via the Graph API?

推荐答案

Marc 在关于列名的评论中说得对,提供的屏幕截图显示 Column.displayName

Marc is right by saying in comment regarding column name, the provided screenshot displays Column.displayName which is

面向用户的列名称.

但实际上 FieldValueSet.AdditionalData 期望作为键的是 Column.name ,它是:

but what actually FieldValueSet.AdditionalData expects as a key is Column.name which is:

列在 字段项目清单.有关面向用户的名称,请参阅 displayName.

The API-facing name of the column as it appears in the fields on a listItem. For the user-facing name, see displayName.

在您的情况下,很可能 displayNamename 属性不同,您可以通过以下端点进行验证:https://graph.microsoft.com/v1.0/sites/root/lists/Outlook Integration/columns

In your case most likely displayName and name properties are different, you could verify it via following endpoint: https://graph.microsoft.com/v1.0/sites/root/lists/Outlook Integration/columns

这就是发生此错误的原因.

and that's the reason why this error occurs.

通过图形 API 客户端 (C#),您可以看到任何给定列表的所有列的列表,如下所示:

Via the Graph API client (C#), you can see a list of all columns for any given list like so:

// get specific list by name
ISiteListsCollectionPage list = await graphClient.Sites["root"].Lists.Request()
    .Filter($"DisplayName eq 'YOUR_LIST_NAME_HERE'").GetAsync();

// get columns and output them to the log as a serialized object
var listColumns = await graphClient.Sites["root"].Lists[list[0].Id].Columns.Request().GetAsync();
logger.LogInformation($"List Columns Object: {JsonConvert.SerializeObject(listColumns).ToString()}");

这篇关于SharePoint 列表项的 AddAsync 上无法识别字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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