Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Can you update a mulivalue choice field via REST API in SharePoint 2010?

If I perform a simple GET I receive:

{
    "d": {
        "__metadata": {
            "uri": "http://dev.domain/sites/plm/_vti_bin/ListData.svc/MarketNeed(1)",
            "etag": "W/\"9\"",
            "type": "Microsoft.SharePoint.DataService.MarketNeedItem"
        },
        "ContentTypeID": "0x0100D93C50E37E1AA144B940BA546F3287FF",
        "Title": "I changed the title.",
        "ProblemStatement": "Shellworker Streetwise A Fret Whishted Shalt Fiver Wool Tv. Hoc Positum In Phaedro A Platone Probavit Epicurus. Theraphosoid Tee Ha, Flip, If Teal If Atwirl A.",
        "RequestorOrganization": {
            "__deferred": {
                "uri": "http://dev.domain/sites/plm/_vti_bin/ListData.svc/MarketNeed(1)/RequestorOrganization"
            }
        },
        "RequestorOrganizationValue": null,
        "Confidentiality": "None",
        "MarketNeedID": "7542f43a-093b-4bd4-a29d-101eea7e166b",
        "Request_ID": "NONE-00001",
        "CustomerRequestor": {
            "__deferred": {
                "uri": "http://dev.domain/sites/plm/_vti_bin/ListData.svc/MarketNeed(1)/CustomerRequestor"
            }
        },
        "CustomerRequestorId": null,
        "ContactInformation": null,
        "Grouping": {
            "results": [
                {
                    "__metadata": {
                        "uri": "http://dev.domain/sites/plm/_vti_bin/ListData.svc/MarketNeedGrouping('System%20Software')",
                        "type": "Microsoft.SharePoint.DataService.MarketNeedGroupingValue"
                    },
                    "Value": "System Software"
                },
                {
                    "__metadata": {
                        "uri": "http://dev.domain/sites/plm/_vti_bin/ListData.svc/MarketNeedGrouping('Factory%20Fit%20System%20Software')",
                        "type": "Microsoft.SharePoint.DataService.MarketNeedGroupingValue"
                    },
                    "Value": "Factory Fit System Software"
                }
            ]
        }
    }
}

I am sending the following payload as a POST with merge and check the etag:

{
"Title":"I changed the title again.",
    "Grouping": {
        "results": [
            {
                "__metadata": {
                    "uri": "http://dev.domain.net/sites/plm/_vti_bin/ListData.svc/MarketNeedGrouping('System%20Software')",
                    "type": "Microsoft.SharePoint.DataService.MarketNeedGroupingValue"
                },
                "Value": "System Software"
            },
            {
                "__metadata": {
                    "uri": "http://dev.domain.net/sites/plm/_vti_bin/ListData.svc/MarketNeedGrouping('Factory%20Fit%20System%20Software')",
                    "type": "Microsoft.SharePoint.DataService.MarketNeedGroupingValue"
                },
                "Value": "Factory Fit System Software"
            },
            {
                "__metadata": {
                    "uri": "http://dev.domain.net/sites/plm/_vti_bin/ListData.svc/MarketNeedGrouping('Special%20Kitting')",
                    "type": "Microsoft.SharePoint.DataService.MarketNeedGroupingValue"
                },
                "Value": "Special Kitting"
            }
        ]
    }
}

And I get the following error:

{
    "error": {
        "code": "",
        "message": {
            "lang": "en-US",
            "value": "Error processing request stream. The payload must represent a valid array format for collections."
        }
    }
}

If I remove the "Grouping" object and just change the title, everything works like a charm. But that is of little use to me.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

To add an item to the array you send a POST to the URL of the item you wish to update: dev.domain.com/sites/plm/_vti_bin/ListData.svc/MarketNeed(1)

with the following payload:

{
    "Grouping": [
        {
            "__metadata": {
                "uri": "http://dev.domain/sites/plm/_vti_bin/ListData.svc/MarketNeedGrouping('Special%20Kitting')",
                "type": "Microsoft.SharePoint.DataService.MarketNeedGroupingValue"
            }
        }
    ]
}

To delete the same selection from the list items choice field you send a DELETE to

dev.domain.com/sites/plm/_vti_bin/ListData.svc/MarketNeed(1)/$links/Grouping('Special%20Kitting')

If you send a payload with the value attribute you will get an error that deep updates are not allowed.

{
    "Grouping": [
        {
            "__metadata": {
                "uri": "http://ctct-dev.ctct.net/sites/plm/_vti_bin/ListData.svc/MarketNeedGrouping('Research')",
                "type": "Microsoft.SharePoint.DataService.MarketNeedGroupingValue"
            },
            "Value":"Research"
        }
    ]
}

To remove all selections from the item's field you would need to post to the URL that is unique to each selection. For example if my list item was returning a "Grouping" field with the following contents:

{
    "Grouping": {
        "results": [
            {
                "__metadata": {
                    "uri": "http://dev.domain/sites/plm/_vti_bin/ListData.svc/MarketNeedGrouping('System%20Software')",
                    "type": "Microsoft.SharePoint.DataService.MarketNeedGroupingValue"
                },
                "Value": "CAES System Software"
            },
            {
                "__metadata": {
                    "uri": "http://dev.domain/sites/plm/_vti_bin/ListData.svc/MarketNeedGrouping('Factory%20Fit%20System%20Software')",
                    "type": "Microsoft.SharePoint.DataService.MarketNeedGroupingValue"
                },
                "Value": "Factory Fit System Software"
            },
            {
                "__metadata": {
                    "uri": "http://dev.domain/sites/plm/_vti_bin/ListData.svc/MarketNeedGrouping('Research')",
                    "type": "Microsoft.SharePoint.DataService.MarketNeedGroupingValue"
                },
                "Value": "Research"
            }
        ]
    }
}

I would need to send separate deletes to 3 URLs .../_vti_bin/ListData.svc/MarketNeed(1)/$links/Grouping('Factory%20Fit%20System%20Software') .../_vti_bin/ListData.svc/MarketNeed(1)/$links/Grouping('Special%20Kitting') .../_vti_bin/ListData.svc/MarketNeed(1)/$links/Grouping('Research')

share|improve this answer
1  
Thanks for posting this. I had to look at this 5 or 6 times and turn my head sideways to get it, but that has more to do with SharePoint than it does your writing. –  Blue Murphy yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.