SPFilterDropdown not working with content type

Feb 5, 2012 at 12:24 AM

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

$().SPServices.SPFilterDropdown({
  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 9: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 7:10 PM

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

Feb 5, 2012 at 11:03 PM

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

Feb 5, 2012 at 11:21 PM

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

From: ChristopheHumbert [email removed]
Sent: Sunday, February 05, 2012 7:04 PM
To: evilgenius@cox.net
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 12: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.

Coordinator
Feb 6, 2012 at 1:07 PM
Edited Feb 6, 2012 at 3: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.

M.

Feb 6, 2012 at 3: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.

Coordinator
Feb 6, 2012 at 5: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?

M.

Feb 6, 2012 at 6: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.

Coordinator
Feb 6, 2012 at 6: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?

M.

Coordinator
Feb 6, 2012 at 6:50 PM

Christophe:

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.

M.

Coordinator
Feb 6, 2012 at 6: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...

M.

Coordinator
Feb 6, 2012 at 7:27 PM
Edited Feb 6, 2012 at 7:34 PM

Christophe:

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

http://spservices.codeplex.com/releases/view/77486

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

M.

Feb 6, 2012 at 7:55 PM

Issue fixed, thanks for the help Marc!

May 21, 2013 at 6:14 AM
Hi,
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:

$().SPServices.SPFilterDropdown({
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.