Search code examples
sharepointspservices

Using SharePoint SPServices


How to set values to a multi choice field using SPServices in SharePoint ?

  1. This Code worked

    $().SPServices({
                   operation: "UpdateListItems",
                   async: false,
                   batchCmd: "Update",
                   listName: "Projets",
                   ID: 53,
                   valuepairs: [
                       ["ProjectName", "Project"],
                       ["ProjectType", "OPPS"],
                       ["ConcernedServices", JSON.stringify($('#select-multiple-optgroups').val())],
                       ["Cible", "Résidentiel"],
                       ["DateRFF", "2014-12-31"],
                       ["DateLancementPrevisionnelle", "2014-12-31"],
                       ["DateDeFin", "2014-12-31"],
                       ["Priorite", "PA"],
                       ["Concept", "dfsf"],
                       ["Reference", "FDF"],
                   ],
                   completefunc: function (xData, Status) {
    
       }});
    
  2. But if I want to add multiple choice doesn't work

    $().SPServices({
                   operation: "UpdateListItems",
                   async: false,
                   batchCmd: "Update",
                   webURL: "/sites/ep/",
                   listName: "Projets",
                   ID: 53,
                   valuepairs: [
                       ["ProjectName", "Project"],
                       ["ProjectType", "OPPS"],
                       ["ConcernedServices", JSON.stringify($('#select-multiple-optgroups').val())],
                       ["Cible", "Résidentiel, Business"],
                       ["DateRFF", "2014-12-31"],
                       ["DateLancementPrevisionnelle", "2014-12-31"],
                       ["DateDeFin", "2014-12-31"],
                       ["Priorite", "PA"],
                       ["Concept", "dfsf"],
                       ["Reference", "FDF"],
                   ],
                   completefunc: function (xData, Status) {
    
       }});
    

Cible is a Multiple Choice field in a sharepoint List.


Solution

  • Since SPServices is calling the OOB webservices behind the scenes, in theory the standard means of updating multiple choice values should come into play: Delimit the values with ;#

    E.g.

    ";#Résidentiel;#Business;#"
    

    Note: Order matters. Make sure values are specified in the same order they're defined in the column