0

I have a list inside SharePoint online site collection. the list contain a field named Processed which is of type single line of text, and only one item have a value inside this field while the other does not have values.

I write this CAL query to get the single item:

List oList = context.Site.RootWeb.Lists.GetByTitle(listname);
                CamlQuery camlQuery2 = new CamlQuery();
                camlQuery2.ViewXml = "<Query><Where><Contain><FieldRef Name='Processed'/>" +
                    "<Value Type='String'>Not Processed</Value></Contain></Where></Query>";

                ListItemCollection collListItem2 = oList.GetItems(camlQuery2);
                context.Load(collListItem2);
                context.ExecuteQuery();
                foreach (ListItem li in collListItem2)

but this CAML returned all the items, although one item has the correct value, while the other have empty/null value for the Processed field.

Any advice to resolve this issue?

1 Answer 1

1

Try using below query in ViewXml (Use internal name of Processed field):

<View>
    <Query>
        <Where>
            <Contains>
                <FieldRef Name='Processed'/><Value Type='Text'>Not Processed</Value>
            </Contains>
        </Where>
    </Query>
</View>

You can also add below to set the row limit to 1:

<RowLimit>1</RowLimit>

official documentations:

  1. How to: Retrieve List Items.
  2. Query schema.
2

Your Answer

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

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