13

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.

15

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
11

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, privacy policy and cookie policy

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