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.

up vote 14 down vote accepted

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!

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

Try ContentTypeId in the CAMLQuery:

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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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