【问题标题】:Update list item multiple lookup value field Microsoft Graph更新列表项多个查找值字段 Microsoft Graph
【发布时间】:2020-04-27 14:18:47
【问题描述】:

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

我尝试了以下代码:

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);

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

【问题讨论】:

    标签: c# api microsoft-graph-api sharepoint-online


    【解决方案1】:

    要设置 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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-14
      • 1970-01-01
      相关资源
      最近更新 更多