Adding IsNotNull and ViewFields in CAML Query
-
09-12-2019 - |
Question
Trying to add IsNotNull parameter and ViewFields paramter but throwing an error. Am I inserting incorrectly or missing something to make sure this executes correctly? Seems like View is bring back all of the items in the list and just need the item I was original returning before needing to add these other parameter
SPQuery myquery = new SPQuery();
myquery.Query =
"<View>" +
"<Where>" +
"<And>" +
"<Contains>" +
"<FieldRef Name='Group' />" +
"<Value Type='Text'>City</Value>" +
"</Contains>" +
"<Eq>" +
"<FieldRef Name='System' />" +
"<Value Type='Text'>" + Param.var.ToString() + "</Value>" +
"</Eq>" +
"<And>" +
"<IsNotNull>" +
"<FieldRef Name='Email' />" +
"</IsNotNull>" +
"</And>" +
"<ViewFields>" +
"<FieldRef Name='Email' />" +
"</ViewFields>" +
"</And>" +
"</Where>" +
"</View>";
Solution
You don't use ViewFields inside the Where clause in a CAML query. See Query Schema and SPQuery.ViewFields Property
Also, the And around the IsNotNull node is doing nothing. The And needs two child elements to operate correctly.
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange