Why can't I set multi-choice values in SharePoint list using WCF REST interface?


  • I'm having very specific trouble using the SharePoint 2010 REST interfaces with a multi-choice column (e.g. a set of checkboxes). Single choice columns work fine (e.g. radio buttons or dropdown, and even yes/no columns all work ok.

    - I have a list 'Flight' on SharePoint with a multi-choice column 'Equipment'

    - in C#, .NET 4.0, I add a Service Reference to the site's RESTful service

    - in the Object Browser in VC# Express, I see the Flight object

    - there is also a FlightEquipmentValue type and a DataServiceCollection<FlightEquipmentValue> Equipment property to set.

    I'm able to instantiate a new context for the service, create a new item, set its other properties. Then I can call FlightEquipmentValue.CreateFlightEquipmentValue() to create a new 'holder' for a checkbox value and add one of my choices to the list of equipment (e.g. "Beverage Cart").

    When I inspect the Flight object in the debugger after adding the equipment, everything looks great. When I save the object with SaveChanges(), the new list item is created in SharePoint.

    Except that the Equipment field is blank, nothing is ever set.

    After trying everything I could think of to set the value (e.g. AttachLink()), .... I sniffed the data going across the wire to the SharePoint service with Fiddler.

    The rest of the Flight object is "serialized" there but not the Equipment field. Nothing at all.

    Help needed, thanks.

           static void Main(string[] args)
                Uri uri = new Uri(args[0]);
                Console.WriteLine("Forwarding: to " + uri);
                HomeDataContext context =
                    new HomeDataContext(uri);
                context.Credentials = new System.Net.NetworkCredential(args[1], args[2]);
                FlightsItem flight = new FlightsItem();
                flight.FlightNumber = "79";
                flight.Pilot = "Bill";
                flight.Copilot = "Susan";
                flight.Aircraft = FlightsAircraftValue.CreateFlightsAircraftValue("Boeing 747");
                flight.AircraftValue = "Boing 737";
                FlightsEquipmentValue equip = FlightsEquipmentValue.CreateFlightsEquipmentValue("Beverage Cart");

    Here's what went over the wire:

        <?xml version="1.0" encoding="utf-8" standalone="yes"?>
        <entry xmlns:d="" 
          <category scheme="" 
           term="Microsoft.SharePoint.DataService.FlightsItem" />
          <title type="text">79</title>
            <name />
          <id />
          <content type="application/xml">
              <d:AircraftValue m:null="true" />
              <d:ContentType m:null="true" />
              <d:ContentTypeID m:null="true" />
              <d:Created m:type="Edm.DateTime" m:null="true" />
              <d:CreatedById m:type="Edm.Int32" m:null="true" />
              <d:Id m:type="Edm.Int32">0</d:Id>
              <d:Modified m:type="Edm.DateTime" m:null="true" />
              <d:ModifiedById m:type="Edm.Int32" m:null="true" />
              <d:Owshiddenversion m:type="Edm.Int32" m:null="true" />
              <d:Path m:null="true" />
              <d:Version m:null="true" />

    Thursday, June 14, 2012 8:43 AM

All replies

  • Hi Per,

    Thanks for your post!

    I am trying to involve some one familiar with this topic to do some further research.


    Simon Huang

    TechNet Community Support

    Monday, June 18, 2012 8:11 AM
  • I’m having the same problem. The DataServiceCollection in the Object Model is populated but the REST-Post doesn’t contain any items.

    Sharepoint Hosting und Beratung

    Tuesday, June 19, 2012 3:12 PM
  • Simon,

    I found a solution but I'd still be curious to hear from an expert.


    This works... 

    // The new objects
    FlightsEquipmentValue equip = FlightsEquipmentValue.CreateFlightsEquipmentValue("Beverage Cart");
    // Make the context start tracking these objects. Note the special name!!!
    context.AttachTo("FlightsEquipment", equip);
    // Track the parent
    // Then add to the choices
    // Now make sure that links are added. Without this, they aren't added!
    context.AddLink(flight, "Equipment", equip);

    I'm not sure I can explain the 'why' of it but the two important points: the order above and the "FlightsEquipment" label the 'equip' object gets attached with.

    I'd been thinking that I needed to attach 'equip' to the entity 'Equipment' where it gets used but that's not the case.

    Hope that helps.

    Before you get too far along the question I faced after fixing this one: I still can't find a way to set a fill-in value on multi-choice fields.

    Since the new fill-in value doesn't exist in the list, and the Value type for the multi-choice field can't be expanded programmatically, I can't get it to accept any new values. Any ideas?

    Regards, Per

    Wednesday, June 20, 2012 3:29 AM
  • Hello Per,

    Can you post the code you are using to attempt a fill-in value, and the results when you attempt to run it (e.g. field is set to blank value or you get an exception)?

    Thank you.

    David Wilborn MSFT

    Monday, July 2, 2012 3:28 PM