Certified for SharePoint 2007 Certified for SharePoint 2010


The SPFilterDropdown function allows you to filter the values available in a Lookup column using CAML against the Lookup column's source list.  This function works with all three types of "dropdown": <20 options (simple select), 20+ options (complex select), and multi-select.
Thanks to Alex Lee (alexlee797) and Ryan (rnshaw) for contributing their versions of this function, which I used to build the one available here. You can see their versions in these two discussion threads: Filter Dropdowns and SPCascadeDropDowns - CAML query on parent column?


  • The relationship list contains the relationshipListColumn
  • The dropdown for columnName is a lookup into relationshipList's relationshipListColumn OR a list column which is a lookup into another list column ("secondary list").


relationshipWebURL: "",
relationshipList: "",
relationshipListColumn: "",
  relationshipListSortAscending: true, // Added in 2013.01
relationshipListSortColumn: "",
columnName: "",
 listName: $().SPServices.SPListNameFromUrl(),
 promptText: "",
noneText: "(None)",
CAMLQuery: "",
 CAMLQueryOptions: "<QueryOptions></QueryOptions>",
completefunc: null,
debug: false

The URL of the Web (site) which contains the relationshipList. If not specified, the current site is used. Examples would be: "/", "/Accounting", "/Departments/HR", etc. Note: It's always best to use relative URLs.

The name or GUID of the list which contains the parent/child relationships. If you choose to use the GUID, it should look like: "{E73FEA09-CF8F-4B30-88C7-6FA996EE1706}". Note also that if you use the GUID, you do not need to specify the relationshipWebURL if the list is in another site.

The StaticName of the column in the relationshipList which is used for the lookup column

If specified, sort the options in the dropdown by this column otherwise the options are sorted by relationshipListColumn

Allows sorting either ascending (true) or descending (false). The default is true (ascending).

The DisplayName of the child column in the form

By default, set to the list name for the current context based on the URL. If your form is outside the context of the list, then you can specify the listName yourself.

Text to use as prompt. If included, {0} will be replaced with the value of childColumn. The default value is "".
NOTE: I discourage the use of this option. Yes, I put it into the function, but if the user doesn't make a choice, they get an ugly error because SharePoint doesn't understand it as an option. I've left in in for backward compatibility.
Deprecated in v0.7.1.

Text to use for the (None) selection. Provided for non-English language support. The default value is "(None)".

The CAMLQuery option allows you to specify the filter on the relationshipList. The additional filter will be <And>ed with the existing CAML which is checking for matching items based on the parentColumn selection. The CAMLQuery should contain a CAML fragment such as:

CAMLQuery: "<Eq><FieldRef Name='Status'/><Value Type='Text'>Active</Value></Eq>"

This option can be used to specify additional options for retrieval from the sourceList. See the MSDN documentation for GetListItems for the syntax.

If specified, the completefunc will be called upon completion of the filtering. Uses for the completefunc: consistent default formatting overrides, additional lookup customizations, image manipulations, etc. You can pass your completefunc in either of these two ways:

completefunc: function() { something...
completefunc: doSomething,                  // Where doSomething is the name of your function
Setting debug: true indicates that you would like to receive messages if anything obvious is wrong with the function call, like using a column name which doesn't exist. I call this debug mode.


In this example, we'll filter the lookup column called "Country" so that we only include those Countries where the Active column is set to 'Yes'. In the screenshot below, you can see that Canada is not currently 'Active'.


In the Sales Opportunities list, we have a lookup column called Country, which gets its values from the Title column in the Countries list.


If we add the call to SPFilterDropdown below...

  relationshipList: "Countries",
  relationshipListColumn: "Title",
  columnName: "Country",
  CAMLQuery: "<Eq><FieldRef Name='Active' /><Value Type='Boolean'>1</Value></Eq>",
  completefunc: null,
  debug: false

...then 'Canada' is filtered out of the available values because it is not 'Active'.


Last edited May 8, 2013 at 4:59 AM by sympmarc, version 18


JSdream Jan 29 at 5:29 PM 
Will this to work with a content type, used in a document library, using a site column lookup to another list. I get no errors, following the documentation. The lookup replaces its possible selections with (None), after running the error free script. The Title column in the child list holds a match for the Query. You mention that the Query gets 'Anded'. I surmise the the intial lookup with all its values, is what gets my Query 'anded' too.

//alert (BranchFolder); //this is a previous variable I get in my script
var TransitNo = BranchFolder.substring(0,5); //I then parseout the number from the name
relationshipList: "Transit Unit Information",
realtionshipListColumn: "Adjudicator_x0020_Names",
columnName: "TestSelectAdjudicator",
CAMLQuery: "<Eq><FieldRef Name='Title' /><Value Type='Text'>" + TransitNo +"</Value></Eq>",
completefunc: null,
debug: false

JSdream Jan 28 at 2:49 PM 
Will the CAMLQuery Fragment allow?: "<Contains><FieldRef Name = 'thecolumnname' /><Value Type='Text'>" + variable + "</Value></Contains>"

TFerraresi Aug 5, 2013 at 7:39 PM 
Hello someone could do in sharepoint 2013 foundacion ??

thamera May 22, 2013 at 3:54 PM 
Is there an easy way of getting options such as "columnName" in this function to allow choosing between static or display name? We are deploying a system in which there is a business requirement to allow users to change the display name on any column to suit their project needs but we want to maintain a single consistent implementation of spservice utilizaiton through a global js on all sites. This means we must be able to use static name "everywhere" as opposed to the display name. I know we can get the static name through other api calls but I am hoping to get this capability within the actual functions rather than additional overhead from needing to always "get" the static name.

thamera Apr 17, 2013 at 9:08 PM 
Has anyone looked at this in 2013 yet? I am using SPServices pretty heavily on a 2013 onprem and this is my first issue. I am getting an error at line 2120 (unminified vesion 0.7.2). It looks like it is looking for a button in the multi-select lookup element but in 2013 there doesn't appear to be a button. Rather, they styled an input element. I would love to see a fix for this against the current stable version (0.7.2) so that I could use it right away. Any thoughts?

AndreyBizin Nov 30, 2012 at 12:56 PM 
wassim87, look for CALM query description.
my example:
<And><Or><Eq><FieldRef Name='Supervisor' /><Value Type='Text'>"+userTitle+"</Value></Eq><Eq><FieldRef Name='EscalatedTo' /><Value Type='Text'>"+userTitle+"</Value></Eq></Or><And><Neq><FieldRef Name='Status' /><Value Type='Text'>Resolved</Value></Neq><Neq><FieldRef Name='Status' /><Value Type='Text'>Rejected</Value></Neq></And></And>

wassim87 May 25, 2012 at 5:23 PM 
This function is amazing, but it only works with me when I have one condition in the query. I tried to do OR operator in the query on the same column but it didn't work, this was my syntax "<OR><Eq><Eq><Eq></Eq></OR>" ... isn't that right?

jaxkookie Aug 25, 2011 at 8:51 PM 
is there a way to just create a dropdown with this method that only return unique items. I want to populate a drop down from a SP column