Search code examples
sharepoint.net-coremicrosoft-graph-apimicrosoft-graph-files

MS GRAPH FieldValueSet for Updating a Person Field with graph .NET API


I tried to update a Person filed named "CurrentAssignedTo" like so:

var fieldValueSet = new FieldValueSet                {
    AdditionalData = new Dictionary<string, object>(){
    {"CurrentQueue", "Editor"},{"JobStatus", $"Questions answered by {comm.User}"}, 
    {"CurrentAssignedToId", comm.Editor.Id.ToString()}        }                };

But the line:

await graphClient.Sites[site.Id].Lists[list.Id].Items[items[0].Id].Fields.Request().UpdateAsync(fieldValueSet);

Errors on the name "CurrentAssignedToId" (Like I used to do with SharePoint API)

But if I use "CurrentAssignedTo" it does not update the person field.

Anyone knows how to make it work? Thanks


Solution

  • In Graph API, should append LookupId after person field name like below:

    Update: the person field value should be int value not string value.

    GraphServiceClient graphClient = new GraphServiceClient(authProvider);

        var fieldValueSet = new FieldValueSet
        {
            AdditionalData = new Dictionary<string, object>()
            {
                {"Title", "Title123"},
                {"CurrentAssignedToLookupId", 15}
            }
        };
    
        var result = graphClient.Sites["siteId"].Lists["ListId"].Items["ItemId"].Fields.Request().UpdateAsync(fieldValueSet);
    

    enter image description here