0

A couple of my rows are Multi Select Rows. When I make this call nothing returns for that row. How do would I handle the multi-value field?

  <script type="text/javascript">
      $.ajax({
          url: "https://gumdropsgc.sharepoint.com/sites/Training/_api/web/lists/getbytitle('Modules')/items(1)",
          type: "GET",
          headers: {"Accept": "application/json;odata=verbose"},
          cache:false,                
          success: function(data){
              console.log(data);
              var html = "<table border='0'>";
              $(data.d.results[0]).each(function(){
              html = html + "<tr><td>" + this.Title + "</td></tr>" +
                  "<tr><td><h2>" + "Roles           :" + 
                  "   " + this.Roles + "</h2></td></tr>";
              });
              html += "</table>";
              $("#listResult").html(html)
          }
    });
</script>

<div id="listResult"></div>     
1
  • Have you tried checking the value of this.Roles? It should be an object or an array (or an array of objects?). Cannot recall, but adding a breakpoint and checking the value should give you the info you need. – wjervis Jan 29 '15 at 12:59
2

MultiSelect data will be returned in following JSON format

"Roles": {
    "__metadata": {
        "type": "Collection(Edm.String)"
    },
    "results": [
        "Enter Choice #1",
        "Enter Choice #2"
    ]
},

If you want to pull it, then you should use

var roles = '';
for(i=0; i < this.Roles.results.length; i++) {
    roles += this.Roles.results[i];
}
1
  • 1
    Amal, Thanks, I was able to drop just add. this.Roles.results in the current code to pull multi select filed data. This may come in handy during the clean up process. – Bitspider Jan 29 '15 at 13:58
2

Values for a multi-select field should come back as a Collection type. The values for the Collection are available from the results property which is an array.

Here's an example. My multi-select field is Color.

enter image description here

var call = jQuery.ajax({
    url: url,
    type: "GET",
    headers: {
        Accept: "application/json;odata=verbose"
    },
    success: function (data, textStatus, jqXHR) {
        var message = jQuery("#message");
        message.text("Items");
        jQuery.each(data.d.results, function (key, value) {
            message.append("<br/>");
            var item = String.format("{0}, [{1}]",
                value.Title, value.Color.results.join(","));
            message.append(item);
        });
    },
    fail: failHandler
});
1
  • Rob, Thanks for the response. I'll need to recode my SP2013 Online page a bit to try this out. I'll make note of it and give it a go in a bit. – Bitspider Jan 29 '15 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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