简体   繁体   中英

.NET Graph SDK Updating Choice Column values in Sharepoint Online

I would like to update the value of a "choice column" but when I call the UpdateAsync method it throws an exception with the following message "Code: invalidRequest - Message: Invalid request".

In previous versions of Sharepoint, the values of the choice columns were separated by ";#" characters, but with Microsoft Graph and Sharepoint Online it seems that this requirement has changed to an array of values. At least I think so...

Any ideas on how to solve this problem?

I am using the following code:

var fieldValueSet = new FieldValueSet
{
    AdditionalData = new Dictionary<string, object>()
    {
        {"Field1", "Test1"},
        { "Field2", ["Test2-A", "Test2-B", "Test3-C"]}
    }
};    
await graphClient
    .Sites["{site-id}"]]
    .Lists["{list-id}"]]
    .Items["{listItem-id}"]
    .Fields
    .Request()
    .UpdateAsync(fieldValueSet);```

You need to add a field to specify that the value for Field2 is an array of strings. Collection(Edm.String) .

Also send the array of values in string "[\"Test2-A\",\"Test2-B\",\"Test3-C\"]"

var fieldValueSet = new FieldValueSet
{
    AdditionalData = new Dictionary<string, object>()
    {
        {"Field1", "Test1"},
        {"Field2@odata.type", "Collection(Edm.String)"},
        {"Field2", "[\"Test2-A\",\"Test2-B\",\"Test3-C\"]"}
    }
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM