Marek Kyzivát
Marek Kyzivát

Reputation: 343

FieldValueSet part underlined while trying to update item in SharePoint Online list

I am trying to update an item from the list via MS Graph.

Tried to follow https://learn.microsoft.com/en-us/graph/api/listitem-update?view=graph-rest-1.0&tabs=cs, but the code below underlines the Color and Quantity and I can't convince it to work.

Screenshot with the issue here

Also tried to follow .NET Graph SDK Updating Sharepoint Online List Item Values, but could not make it to work as well.

Tried with new ListItem as variable too as could be seen in some older cases, but now it just wants the FieldValueSet and would not accept the ListItem.

var fieldValueSet = new FieldValueSet
{
Color = "Fuchsia",
Quantity = 934
};

    await graphClient.Sites["yourtenant.sharepoint.com:/sites/ITOddeleni:"].Lists["TeamsRequest"].Items[item.Id].Fields
.Request()
.UpdateAsync(fieldValueSet);

Upvotes: 1

Views: 1122

Answers (2)

Katrin
Katrin

Reputation: 21

The accepted answer is not working anymore.

var fieldValueSet = new FieldValueSet();
fieldValueSet.additionalDataManager().put("Title", new JsonPrimitive("new Title value"));

Upvotes: 0

Marek Kyzivát
Marek Kyzivát

Reputation: 343

Finally, my colleague helped me out to come up with this :-)

var fieldValueSet = new FieldValueSet();
                                fieldValueSet.AdditionalData = new Dictionary<string, object>();
                                fieldValueSet.AdditionalData.Add("[email protected]", "Edm.String");
                                fieldValueSet.AdditionalData.Add("ColumnName", "DesiredValue");



                                await graphServiceClient.Sites["yourtenant.sharepoint.com:/sites/ITOddeleni:"].Lists["TeamsRequest"].Items[item.Id].Fields
                                    .Request()
                                    .UpdateAsync(fieldValueSet);

Upvotes: 2

Related Questions