0

I have a list with columns "fruit" and "ripeness". Using csom, how can I return "Banana" where Yellow count >= 3?

ClientContext ctx = new ClientContext("https://sharepoint.blah.com");
List list = ctx.Web.Lists.GetByTitle("Log");
ctx.Load(list);
ctx.ExecuteQuery();
CamlQuery query = new CamlQuery();
ListItemCollection items = list.GetItems(query);
ctx.Load(items);
ctx.ExecuteQuery();
0

Considering that you have a column named 'Yellow' and typed number, and you wish to get all items have more then 3 in their 'Yellow ' column.

ClientContext ctx = new ClientContext("https://sharepoint.blah.com");
List list = ctx.Web.Lists.GetByTitle("Log");
ctx.Load(list);
ctx.ExecuteQuery();
CamlQuery query = new CamlQuery();
query.ViewXml
    = "<Where><Geq>"
    + "<FieldRef Name='Yellow'/><Value Type='Number'>"
    + "3</Value></Geq></Where>";
ListItemCollection items = list.GetItems(query);
ctx.Load(items);
ctx.ExecuteQuery();


  • Sorry... I want to show banana if there are >= 3 instances of Banana, Yellow. – samt Aug 13 at 17:39
0

You cannot use this kind of complex query is you don't have column 'Yellow' and its count. Assuming your ripeness column has value Yellow you can use below code.

ClientContext ctx = new ClientContext("https://sharepoint.blah.com");
List list = ctx.Web.Lists.GetByTitle("Log");
ctx.Load(list);
ctx.ExecuteQuery();
CamlQuery query = new CamlQuery();
query.ViewXml
    = "<Where><And>"
    + "<Eq><FieldRef Name='Fruit'/><Value Type='Text'>Banana</Value></Eq>"
    + "<Eq><FieldRef Name='Ripeness'/><Value Type='Text'>Yellow</Value></Eq>"
    + "</And></And></Where>";
ListItemCollection items = list.GetItems(query);
ctx.Load(items);
ctx.ExecuteQuery();

if(items.Count >=3)
{
    //use any one item from items object as items[0] - This will always be banana
    // display as you want
}

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.