2

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?

6
  • have a look this link which might help you solve your issue:blogs.msdn.com/b/officeapps/archive/2012/11/29/…
    – Supermode
    Commented Jul 21, 2014 at 0:47
  • you wrote this: read from webapp2/sites/sitecoll2 into an app that is deployed to webapp2/sites/sitecoll2. Where are these different site collections?
    – Gwny
    Commented Jul 21, 2014 at 7:08
  • @user1901384 Thanks for noticing the error in the url. I've corrected it now. It is from sitecoll2 to sitecoll1 and both are in the same web application which is webapp2. This works. Only different web application doesn't work. Commented Jul 26, 2014 at 17:22
  • It might be a limitation of the app model. Not sure how tenant permissions translate to the onprem environment. Try making the rest call in a CEWP. That'll at least let you know where the restriction is.
    – wjervis
    Commented Jul 26, 2014 at 17:25
  • @Supermode Thanks for the link. I had already used that as reference to build an app that accessed data across two different site collections. However, it fails when the site collections are in different web applications. Commented Jul 26, 2014 at 17:46

1 Answer 1

-1

Never put the domain of the site, eg:

../../_api/web/lists/getbytitle('LIST')/items() // If the script is a list 
../_api/web/lists/getbytitle('LIST')/items() // If the script is on a page 

If you want to change the webApllication, just do this:

../../../WEBApllcation/_api/web/lists/getbytitle('LIST')/items()

I have always done this way:

$.ajax({   
    async: true,
    url: "../../_api/web/lists/getbytitle('List')/items?$top=10000",
    method: "GET",
    headers: { "Accept": "application/json; odata=verbose" },
    success: function(servic){
        for(var i=0;i<service.d.results.length;i++){

        }
    }
});

Hope this helps, anything I am available

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.