繁体   English   中英

更新列表项多个查找值字段 Microsoft Graph

[英]Update list item multiple lookup value field Microsoft Graph

我正在尝试更新列表项的多个查找值字段。

我尝试了以下代码:

List < QueryOption > options = new List < QueryOption > {
    new QueryOption("$expand", "listitem")
};
//get drive item with list item
var driveItem = graphClient.Sites[IdGestDoc].Drive.Items[itemResult.Id].Request(options).GetAsync().Result;
var fieldValueSet = new FieldValueSet {
    AdditionalData = new Dictionary < string,
    object > {
        {
            "Theme_fonctionnel@odata.type",
            "Collection(Edm.String)"
        }, {
            "Theme_fonctionnel", ThemeFonctionnel.ToArray()
        } //ThemeFonctionnel is a List<string> => lookupid
    }
};
await graphClient.Sites[IdGestDoc].Lists["Documents"].Items[driveItem.ListItem.Id].Fields.Request().UpdateAsync(fieldValueSet);

但是这段代码不起作用,我找不到我所缺少的。 任何帮助将不胜感激 !

要设置 Lookup 字段,您需要通过传入属性名称和添加的“LookupId”来设置属性:

        string propertyName = "Theme_fonctionnel";

        var fieldValueSet = new FieldValueSet();

        var propertyValuesArray = options.ToArray();

        var attributes = new Dictionary<string, object>();

        //first, we need to specify the input data type
        string oDataTypeInfoPropertyName = propertyName + "LookupId@odata.type";
        string oDataDataType = "Collection(Edm.String)";
        attributes.Add(oDataTypeInfoPropertyName, oDataDataType);

        //next, we need to pass the values as an array
        string newPropertyName = propertyName + "LookupId";
        attributes.Add(newPropertyName, propertyValuesArray);

        fieldValueSet.AdditionalData = attributes;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM