SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can you get distinct values from a SharePoint List column using JavaScript without a huge performance hit?

A simple example would be appreciated :)

share|improve this question
How many items you suppose to query? (maximum count) – Kai Jan 18 '12 at 22:16
Whats the field type - is it a Choice/MultiChoice (and do you allow 'fill in' values) or something else? – Ryan Jan 19 '12 at 8:28
At the moment I'm looking at 100+ items, but that could get a lot more over time id recon. In some lists I have choice fields Ryan, other there is People Picker fields – Anders Aune Jan 19 '12 at 11:15
up vote 3 down vote accepted

Assuming that your field is a Choice/MultiChoice field without "Fill In Choices" enabled then you can use get_choices.

If it does have fill in choices and/or is a different field type then I don't think there is an option apart from brute force (iter over all items getting unique values).

<script type="text/ecmascript">

function GetChoiceValues() {
  var context = new SP.ClientContext.get_current();    
  var web = context.get_web();    

  // Get the list
  var taskList = web.get_lists().getByTitle("list");

  // Get Department choice field (choice field)
  var deptChoiceField = 

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

function onSuccessMethod(sender, args) {
    var choices = deptChoiceField.get_choices();
    alert("Choices: (" + choices.length + ") - " + choices.join(", "));

function onFailureMethod(sender, args) {
    alert("failed. Message:" + args.get_message());

share|improve this answer
Thank you, this will help me a lot on the way :) – Anders Aune Jan 19 '12 at 11:16

I personally prefer /_vti_bin/listdata.svc. For example to retrieve only Title och Status from 100 first Tasks:

http://dev/_vti_bin/listdata.svc/Tasks()?$select=Title, StatusValue&top=100

See more on my blog: $select, $.getJSON and listdata.svc, updating with listdata.svc

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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