1

I am building API for client side apps. There are 3 API requests for 3 different lists as following:

tasksQuery = string.Format(@"<Where><And><Geq><FieldRef Name='Created' /><Value IncludeTimeValue='TRUE' Type='DateTime'>" + FromDate + "</Value></Geq><And><Eq><FieldRef Name='TaskCompleted' /><Value Type='Boolean'>0</Value></Eq><Or><Eq><FieldRef Name='CreatedBy' /><Value Type='Text'>" + LoggedUser + "</Value></Eq><Or><Eq><FieldRef Name='Responsible' /><Value Type='Text'>" + LoggedUser + "</Value></Eq><Or><Eq><FieldRef Name='Accountable' /><Value Type='Text'>" + LoggedUser + "</Value></Eq><Or><Contains><FieldRef Name='Consulted' /><Value Type='Note'>" + LoggedUser + "</Value></Contains><Contains><FieldRef Name='Informed' /><Value Type='Note'>" + LoggedUser + "</Value></Contains></Or></Or></Or></Or></And></And></Where>")

meetingQuery = string.Format(@"<Where><And><Geq><FieldRef Name='Created' /><Value IncludeTimeValue='TRUE' Type='DateTime'>" + FromDate + "</Value></Geq><Or><Eq><FieldRef Name='Organizer' /><Value Type='Text'>" + LoggedUser + "</Value></Eq><Eq><FieldRef Name='Creator' /><Value Type='Text'>" + LoggedUser + "</Value></Eq></Or></And></Where>")

newsQuery = string.Format(@"<Where><Eq><FieldRef Name='Status' /><Value Type='Text'>1</Value></Eq></Where><OrderBy><FieldRef Name='NewsArticleDate' Ascending='False' /></OrderBy>";

How can I combine all these queries in one query?

1

You're not able to combine those queries into a single CAML-query but you can query all those items in the same request, ex:

List tasksList = context.Web.Lists.GetByTitle("Tasks");
List meetingList = context.Web.Lists.GetByTitle("Meeting");
List newsList = context.Web.Lists.GetByTitle("News");

CamlQuery tasksQuery = new CamlQuery() { ViewXml = '...' };
CamlQuery meetingQuery = new CamlQuery() { ViewXml = '...' };
CamlQuery newsQuery = new CamlQuery() { ViewXml = '...' };

var tasksItems = tasksList.GetItems(tasksQuery);
var meetingItems = tasksList.GetItems(meetingQuery);
var newsItems = tasksList.GetItems(newsQuery);

context.Load(tasksItems); 
context.Load(meetingItems);
context.Load(newsItems);

context.ExecuteQuery(); 

// Here you can use results of all those queries

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.