16

In a SharePoint list I have a column, created using a custom content type. Let's say, the content types is "MyContentType". I used in a column "My Custom Column".

Need to filter out items if the "My Custom Column" columns value is not null.

But, There are many lists in the site where column name might differ. The program requires to query many lists, in which the column name might differ, so i can't build the query based on column name, instead make use of the Content type name. Can this be achieved using a CAML query alone.

2 Answers 2

19

You can use a SPSiteDataQuery to query multiple lists (within your site structure) and filter based on Content Type. Something like this:

<Where>
  <Eq>
    <FieldRef Name='ContentType'/>
    <Value Type='Computed'>YourCustomContentTypeName</Value>
  </Eq>
</Where>

Tip: Download CAML Designer which will assist you in query building!

2
  • I'm guessing somethings wrong in my end
    – Shaamil
    Commented Feb 7, 2014 at 11:37
  • My Bad. The code works ! Any idea if the list used Field Types instead of content types ?
    – Shaamil
    Commented Feb 7, 2014 at 12:07
12

Try ContentTypeId in the CAMLQuery:

<BeginsWith>
   <FieldRef Name='ContentTypeId' />
   <Value  Type='ContentTypeId'>YourContentTypeIdHere</Value>
</BeginsWith>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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