1

I am trying to find an item in a list where the managed metadata field is equal to a certain text value. This is the code that I have which is not getting any items in the list (ListItemCollection count = 0). Is this the right way to go about the query?

Update: I added loading the list item collection. Now I am getting all of the items in the list

List list = web.Lists.GetByTitle("Name of List"); string textValue = "Meta Data Term Text"; CamlQuery query = new CamlQuery(); query.ViewXml = @"<Where> <Contains> <FieldRef Name='MetaDataFieldInternalName' /> <Value Type='Text'>" + textValue + @"</Value> </Contains> </Where>"; ListItemCollection lColl = list.GetItems(query); clientContext.Load(lColl); //added clientContext.ExecuteQuery(); //added ListItem lItem = lColl[0]; clientContext.Load(lItem, item => item["InternalName1"], item => item["InternalName2"]); clientContext.ExecuteQuery(); 
1
  • 2
    You need to wrap your query in ‘<View>‘ tags in CSOM Commented Jun 2, 2017 at 5:14

2 Answers 2

1

Can you try the following query? I am thinking based on field type it can be format as below.

<Where> <Eq> <FieldRef Name='officelocations' /> <Value Type='TaxonomyFieldTypeMulti'>seattle</Value> </Eq> </Where> 

This is for a multi-value field. The type should be TaxonomyFieldType for single value type field.

0

From @Robert's comment, here is the answer for your query that are missing some tags:

CamlQuery query = new CamlQuery(); query.ViewXml = @"<View Scope='RecursiveAll'> <Query> <Where> <Contains> <FieldRef Name='MetaDataFieldInternalName' /> <Value Type='Text'>" + textValue + "</Value> </Contains> </Where> </Query> </View>"; 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.