0

I need to make a Caml query to filter a list from content type AND for a specific value from a list. For example, a content type ID and a field value "English" from the column "languages" will get all the data/rows from the list with said content type and where languages is equal to "English".

So far I have this:

         `<View><ViewFields><FieldRef Name='BannerImageUrl' />
        <FieldRef Name='intraSubhead' /><FieldRef Name='FileLeafRef' /><FieldRef Name='Title' />
        <FieldRef Name='intraContentCategory' /></ViewFields>
        <Query>
        <Where>
        <And>
        <BeginsWith><FieldRef Name='ContentTypeId'/>
        <Value Type='ContentTypeId'>${contentTypeId}  //I load the content type here

        <Eq>
        <FieldRef Name="intraLanguages" />
        </Value>
         <Value Type="TaxonomyFieldType">${currentLanguage} // value like "English" and so on.
        </Value>
        </Eq>
        </And>
        </BeginsWith>

        </Where></Query>
        </View>`;

As seen above I try to do filter with content type and a value in a taxonomy field (intraLanguages). It doesn't work. Any help?

  • Are you getting any error? If yes, please post it to your question. Also I can see the error in your query. Ending tags are not closed properly. – Ganesh Sanap Jun 4 at 6:40
0

For Content Type:

You can add filter on Content Type using its name or Id as given below:

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

//Using ID of Content Type
<Where>
  <BeginsWith>
     <FieldRef Name='ContentTypeId' />
     <Value  Type='ContentTypeId'>YourContentTypeIdHere</Value>
  </BeginsWith>
</Where>

For Managed Metadata field:

There are 2 methods to query a list/library that contains a managed metadata column:

  1. Query against Term Name
  2. Query Against WSSID

Method 1 (will look something similar to this):

 query.Query = @"<Where>
                  <Contains>
                      <FieldRef Name='" + MyTaxonomyFieldName + @"' />
                      <Value Type='Text'>" + tagName + @"</Value>
                  </Contains>
                </Where>";

Or

<Query><Eq><FieldRef Name=\"ManagedMetadata\"/><Value type=\"string\">brocoli</Value></Eq></Query>

Method 2:

query.Query = @"<Where>
                  <In>
                   <FieldRef LookupId='TRUE' Name='" + MyTaxonomyField + @"' />
                    <Values>
                       <Value Type='Integer'>" + tagLookupID + @"</Value>
                    </Values>
                  </In>
                 </Where>";

It is recommended to use the second method to avoid situations where the term name is used under different term groups.

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.