Wednesday, May 4, 2016

Problem with creating cross-site collection SP.ClientContext and metadata filters in Sharepoint document libraries

Recently we faced with interesting problem in Sharepoint Online site: in one of document libraries we had custom ribbon button. Javascript handler of this button created SP.ClientContext object for different site collection and retrieved some data from this site collection:

   1: var otherSiteCtx = new SP.ClientContext("http://example.com/sites/foo");
   2: var otherSiteWeb = otherSiteCtx.get_web();
   3: otherSiteCtx.load(otherSiteWeb);
   4: otherSiteCtx.executeQueryAsync(
   5:     Function.createDelegate(this, function (sender, args) { ... }),
   6:     Function.createDelegate(this, function (sender, args) {
   7:         console.log("Get site failed: " + args.get_message());
   8:     }));

It worked until we activated Metadata navigation and filtering feature and added Metadata filter to this document library. After that code above started to throw exception:

Unexpected response from server. The status code of response is '403'. The status text of response is 'FORBIDDEN'

In order to avoid the problem we had to disable metadata filter for this document library, i.e. in doclib settings > Metadata navigation settings remove all fields from filter list:

After that javascript handler started to work again. It looks like issue in Sharepoint internal javascript implementation. If you know better solution, please share it in comments.

No comments:

Post a Comment