Using SharePoint SPServices

2.4k Views Asked by At

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.

2

There are 2 best solutions below

1
On BEST ANSWER

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

0
On

I came across this post while trying to achieve the same thing, however this answer didn't work for me. I was eventually able to save multiple values in the lookup field using the following format:

"6;#;#8;#"

Where the numbers are the ID of the list items (to save formatting issues)

With the ID and the title of the list item it looked like this:

"6;#Alcohol:Reports;#4;#Alcohol: News"

Both of these methods successfully inserted the values into the list.