Search code examples
c#microsoft-graph-apimicrosoft-graph-sdksmicrosoft-graph-files

Microsoft Graph SDK 5 upgrade - How to pass a FieldValueSet


I'm struggling upgrading to Microsoft SDK 5.3.0. This code is suppose to set a value to a specific column for a DriveItem.

string key = "SomeColHeader";
string value = "Value1";
             
var fieldValueSet = new FieldValueSet
{
  AdditionalData = new Dictionary<string, object>()
  {
    {key, value}
  }
};

await GraphClient
   .Drives[driveId]
   .Items[driveItemId]
   .ListItem.Fields
   .Request()
   .UpdateAsync(fieldValueSet)

Any help appriciated.


Solution

  • First thing, it's definitely a bug in v 5.3.0 that it's not possible to update FieldValueSet when you access the list item through the endpoint

    PATCH /v1.0/drives/{driveId}/items/{driveItemId}/listItem
    

    As an alternative get listItem and select parentReference and sharepointIds properties. Then access listItem through /sites endpoint

    var listItem = await client
               .Drives[driveId]
               .Items[driveItemId]
               .ListItem.GetAsync(x=>
               {
                   x.QueryParameters.Select = new[] { "id", "parentReference", "sharepointIds" }; 
               });
    
    var result = await client.Sites[listItem.ParentReference.SiteId]
              .Lists[listItem.SharepointIds.ListId]
              .Items[listItem.Id]
              .Fields
              .PatchAsync(fieldValueSet);