5

Is there any equivalent in SharePoint 2013 RESTful API or JavaScript Object Model to either one of the following?

2

Unfortunately I have to write some custom C# code to get it, here what I did:

  1. Create an HttpHandler or WCF service (any service you like)
  2. Write the C# code the convert the data table to JSON
  3. Use that JSON in JavaScript as you want

Here is an example how to get all site collection article pages:

const string ArticleContentTypeId = "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D";
const int PagesListItemplateId = 850;
var camlQuery = String.Format(
                     "<Where>" +
                       "<BeginsWith>" +
                         "<FieldRef Name='ContentTypeId'/>" +
                         "<Value Type='ContentTypeId'>{0}</Value>" +
                       "</BeginsWith>" +
                     "</Where>" +
                     "<OrderBy>" +
                       "<FieldRef Name='ArticleStartDate' Ascending='FALSE' />" +
                     "</OrderBy>", ArticleContentTypeId);
const string ViewFields =
"<FieldRef Name='Title' />" +
"<FieldRef Name='PublishingPageImage' />" +
"<FieldRef Name='PublishingRollupImage' />" +
"<FieldRef Name='PublishingPageContent' />" +
"<FieldRef Name='ArticleStartDate' />" +
"<FieldRef Name='FileRef' />" +
"<FieldRef Name='Comments' />";

CrossListQueryInfo crossListQueryInfo = new CrossListQueryInfo();

crossListQueryInfo.Lists = string.Format("<Lists ServerTemplate='{0}' />", PagesListItemplateId);
crossListQueryInfo.Query = camlQuery;
crossListQueryInfo.ViewFields = ViewFields;
crossListQueryInfo.Webs = "<Webs Scope='Recursive' />";
crossListQueryInfo.UseCache = true;

CrossListQueryCache crossListQueryCache = new CrossListQueryCache(crossListQueryInfo);

DataTable siteArticles = crossListQueryCache.GetSiteData(SPContext.Current.Site);
var response = JsonConvert.SerializeObject(siteArticles);
context.Response.Clear();
context.Response.ContentType = "application/json";
context.Response.Write(response);

https://github.com/Devville/Devville.DataService/blob/master/Devville.DataService/Devville.DataService.SharePointOperations/GetSiteData.cs#L171

1

I'm afraid not...

The CSOM does not provide a mechanism for querying data across multiple lists that are not associated by a lookup field. In other words, there is no client-side functional equivalent of the SPSiteDataQuery class. If you need to perform a cross-list query from client-side code, consider creating a list view on the server that performs the list aggregation. You can then query the aggregated data from your client-side code.

Source: https://msdn.microsoft.com/en-us/library/ff798388.aspx

  • I know that for CSOM for 2010 that's why I put RESTful first on my question – Ahmed Magdy Mar 18 '15 at 5:42

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.