Question

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?

Était-ce utile?

La solution

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.
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top