Ramalingam
Ramalingam

Reputation: 255

Logical AND ,OR CAML Query not working in External List

I am using ClientContext Class and CAML query to retrieve items from External List in sharepoint 2010.I have built the query with Logical AND Condition in CAML Query like this

 string sDataFilter =<Query><Where><And><Eq><FieldRef Name="Year" /><Value Type="Text">1960</Value></Eq><Contains><FieldRef Name="ChartName" /><Value Type="Text">Chart1</Value></Contains></And></Where></Query>

When I exceute the following code

List oList = clientContext.Web.Lists.GetById(new Guid(list));
               CamlQuery camlQuery = new CamlQuery();
               string queryContext = "<View><Query>" + sDataFilter + "</Query>" + viewFieldsContext + "</View>";
               camlQuery.ViewXml = queryContext;
               ListItemCollection collListItem = oList.GetItems(camlQuery);
               clientContext.Load(collListItem);
               clientContext.ExecuteQuery();

I am getting the empty ListItemCollection.I have cross verified with the U2U CAML Query Builder the data is empty only. So in External List the caml query is working fine for sorting and simple filter query like Where,EqualTo condition I can't use Logical conditions in the query ? If yes how could I achieve this using caml query Could anyone help me to resolve this issue ?

Upvotes: 0

Views: 1319

Answers (1)

V_B
V_B

Reputation: 1569

The problem is below line of code

   string queryContext = "<View><Query>" + sDataFilter + "</Query>" + viewFieldsContext + "</View>";

change this line with follwing code

  string queryContext = "<View>" + sDataFilter +  viewFieldsContext + "</View>";

the problem is in Query tag. It's two time repeat in query.
late me know when it's working

Thax

Upvotes: 1

Related Questions