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

SPFilterDropdown not working with content type

Feb 5, 2012 at 1:24 AM

I am trying to filter a lookup based on the content type. For example:

  relationshipList: "SitesAndSubsites",
  relationshipListColumn: "Title",
  columnName: "Site",
  CAMLQuery: "<Eq><FieldRef Name='ContentType' /><Value Type='Text'>Site</Value></Eq>",
  completefunc: null,
  debug: false

(from the SitesAndSubsites list, I only want the items that have a Site content type)

This returns an empty list. What am I missing?

Feb 5, 2012 at 10:53 AM

Hey Christophe! I believe part of the issue is that ContentType in this case is a GUID and not the displayname of the ContentType. At least that is how I have used it in the past. Though you could just do a quick GetListItems test to be sure.

Feb 5, 2012 at 8:10 PM

Thanks for the suggestion. I did a getListItems test and it confirms that the content type is "Site", not a GUID.

Feb 6, 2012 at 12:03 AM

Update: I was able to get this to work by using ContentTypeId and the content type unique Id. Thanks @spevilgenius for the tip!

Feb 6, 2012 at 12:21 AM

I knew it was there somewhere J Glad you got it working!

From: ChristopheHumbert [email removed]
Sent: Sunday, February 05, 2012 7:04 PM
Subject: Re: SPFilterDropdown not working with content type [SPServices:293308]

From: ChristopheHumbert

Update: I was able to get this to work by using ContentTypeId and the content type unique Id. Thanks @spevilgenius for the tip!

Feb 6, 2012 at 1:08 AM

I'd still be interested to get it to work with the content type name. I have found on the Web several examples that use the name, and it would be much easier for maintenance/migration/upgrade purposes.

Feb 6, 2012 at 2:07 PM
Edited Feb 6, 2012 at 4:41 PM

I'm surprised that the text value didn't work. It sounds like you can see the value if you retrieve the items with GetListItems, so it should work in SPFilterDropdown.

It might be useful to step through the unminified code to see if there's some other issue.


Feb 6, 2012 at 4:32 PM

Marc, are you talking about the SPServices code? I went through it, and the only place would be where the CAML query is built.

All the other filters I tried - based on other columns - worked fine.

I'll do some more testing today as I'd really like to see this work.

Feb 6, 2012 at 6:24 PM

I suppose it also depends on what the page you're working with looks like. Can you post the markup from a view source of the part of the form you're working with?


Feb 6, 2012 at 7:09 PM

Well, I would need to do some cleanup as it is from my customer's site. Here is the setup:

  • "Site" is a site content type (child of another content type)
  • the lookup is a required field, single lookup with more than 20 items

Again, all the other configurations worked fine. Only the filter by content type name (the above code) returns an empty list.

Feb 6, 2012 at 7:23 PM

Have you looked at the returned XML to see if there's an error? I'm wondering if there's some issue because the ContentType isn't in the default view for the list. Because you're providing a CAMLQuery, I'd expect the default view to be overridden, but maybe not?


Feb 6, 2012 at 7:50 PM


I just dummied this up in my test environment and it works exactly as you want it to. I wonder what the difference might be? I used the script exactly as you have it in your initial post above.


Feb 6, 2012 at 7:53 PM

Oops. Hold on. I spoke too soon. I just pushed it over 20 items and I'm not seeing the filtering. Under 20 items, it seems to work. Let me debug...


Feb 6, 2012 at 8:27 PM
Edited Feb 6, 2012 at 8:34 PM


I found a bug in the function for 20+ items. I've just posted a new beta which should work:

Let me know if this fixes it, and sorry for any wasted time. But thanks for catching it!


Feb 6, 2012 at 8:55 PM

Issue fixed, thanks for the help Marc!

May 21, 2013 at 7:14 AM
I am using version 0.7.2, and I have the similar issue as describe in this post.
I am using SPFilterDropdown() but as soon as items number is more than 20, filter does not work any more.

Code used below:

relationshipList: "TestList",
relationshipListColumn: "ItemName",
columnName: "ItemName",
CAMLQuery: "<Eq><FieldRef Name='Active'/><Value Type='Boolean'>1</Value></Eq>",
completefunc: null,
debug: true

Can you please advise what I am doing wrong?
Thank you in advance for you help.