Thursday, January 10, 2013

Using Javascript to get all choice values from SharePoint Choice column

Hi all,

Get List of all choice option from SharePoint Choice field with help of Javascript Client Object model




var context = new SP.ClientContext.get_current();

var web = context.get_web();

context.load();

var studList = web.get_lists().getByTitle("students");

var studbatches = context.castTo(studList.get_fields().getByInternalNameOrTitle("batches"), SP.FieldChoice);



context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod),

Function.createDelegate(this, this.onFailureMethod));



function onSuccessMethod(sender, args) {

var choices = studbatches.get_choices();

alert("Choices: (" + choices.length + ") - " + choices.join(", "));

}



function onFailureMethod(sender, args) {

alert("Error...!");

  } 


  Thanks,

 Sachin K. 


 Reference

2 comments:

  1. How to Get all values from a Multiple Choice field from single list in a single call in SharePoint 2010 using JavaScript

    ReplyDelete