Ofer Gal
Ofer Gal

Reputation: 883

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

Upvotes: 1

Views: 1393

Answers (1)

Jerry
Jerry

Reputation: 3615

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

Upvotes: 1

Related Questions