In an on-premises SharePoint 2013 environment I need to read list items stored in a different web application using JavaScript based solution. This could either be JavaScript in Script Editor web part or a Tenant Scoped SharePoint-Hosted App. I've tried using JavaScript object model as well as REST to try and retrieve items across web application but no luck yet. Is this restricted by design?
Here is what worked for me so far - Same web application different site collection. This works!
In a SharePoint-Hosted App with READ permission to tenant, site collection and web and using REST API I'm able to successfully read list items across site collection. This App has been deployed from App Catalog.
For example I'm able to read list item data from http://webapp2/sites/sitecoll2 into an app that is deployed to http://webapp2/sites/sitecoll1. This works as long as its the same web application.
Code that works for same web application different site collection (Tenant Scoped SharePoint-Hosted App)
var appweburl = //Obtained from URL Tokens
function getListItems() {
var targetUrl = "http://webapp2/sites/sitecoll2";
var executor = new SP.RequestExecutor(appweburl);
executor.executeAsync({
url: appweburl + "/_api/SP.AppContextSite(@target)/web/lists/GetByTitle('TestList')/items?$select=Title&@target='" + targetUrl + "'",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
var jsonObject = JSON.parse(data.body);
var listItems = jsonObject.d.results;
jQuery.each(listItems, function (index, item) {
// code to display list items
});
},
error: function (data, errorCode, errorMessage) {
alert("Call failed. Error: " + errorMessage);
}
});
}
Here is what I need - Read list items stored in web application 2 using JavaScript and display in Web Application 1. This does not work.
Is this restricted by design because App Catalog is per web application and cannot "see" site collections in other web applications? Is there a way to access data using JavaScript across web applications in SharePoint 2013 on-premises?