This project has moved and is read-only. For the latest updates, please go here.

$().SPServices GetListItems Distinct Values

Jun 3, 2010 at 10:06 AM


What I am trying to do is to retrieve Distinct values from another List and render them to a Dropdown in another list's NewItem.aspx.

Is it possible to do this OOTB ( in CAML or in $().SPServices Code ) or do I have to check every time for an item if it has been already added?

Thank You,


Jun 3, 2010 at 2:52 PM

I finally fixed my problem by checking if the item was already added to the <select> element.

I used the following snipet:


            operation: "GetListItems",
            listName: "MasterList",
            async: false,
            CAMLQuery: queryDepartment,
            completefunc: function (xData, Status) {
                sCategory = $(this).attr("ows_Certificate_x0020_Category");
                if($('#ctl00_m_g_c827580e_a250_41f1_8e7b_7390ed1eedf3_ctl00_ctl04_ctl01_ctl00_ctl00_ctl04_ctl00_DropDownChoice option[value=' + sCategory + ']').length == 0 )
                    ddlCategory.append("<option value='" + sCategory + "'>" + sCategory + "</option>");    



Jun 3, 2010 at 11:30 PM

Nice. Glad you solved it! Thanks for sharing the solution back here.


Jun 7, 2010 at 3:42 PM


If it's a long list you can used a very fast built in sharepoint function to return unique values. I used something like below (can probably be made more clever...)

function getAjaxFilter(filterName, interalName){
	  url: 'http://YOUR_SITE/_layouts/filter.aspx?ListId=%7BBB2B4096-1B99-413B-AAE6-EAD9EB317E17%7D&FieldInternalName='+interalName+'&ViewId=%7B98E5FC99-631A-4932-9FE6-740515742091%7D&FilterOnly=1&Filter=1',
	  success: function(data) {

Jun 7, 2010 at 9:18 PM

Nice! Is there documentation for this method (the filter.aspx page in particular) anywhere?

For others, you'll need to replace the ListId and ViewId with valid GUIDs for your own environment.


Jun 14, 2010 at 5:54 PM

I never found any documentation about this, just looked at the generated source when filtering a list.

You can even get unique values when adding a "second filter"


or if used as source in an iframe



May 13, 2014 at 7:18 PM
I'm about 4 years late to this party, but I was having the exact same issue earlier today and quickly found a very simple jQuery solution (credit to StackOverflow). It (appears) to loop through all of your drop-down's options and removes any duplicate text values.

$(document).ready(function() {

var usedNames = {};
$("select[name='divSel'] > option").each(function () {
    if(usedNames[this.text]) {
    } else {
        usedNames[this.text] = this.value;

<select id="divSel" name="divSel" style="width:475px;" onchange="selectDate();" />

Hopefully this helps anyone else looking for the same functionality!