Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am trying to get title of a list which is located on Host Site from an SharePoint hosted app by using csom (javascript). I have added permission on Manifest file and chose the list but still getting Access denied on executeQueryAsync. here is my code:

  hostweburl = decodeURIComponent(getQueryStringParameter('SPHostUrl'));
  var hostcontext = new SP.ClientContext(hostweburl);
  var oList = hostcontext.get_web().get_lists().getByTitle('SliderList');
  var camlQuery = new SP.CamlQuery();
  camlQuery.set_viewXml(' som query to get proper items')
  this.collListItem = oList.getItems(camlQuery);

   hostcontext.load(collListItem);

   hostcontext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

it does not go to either onQuerySuccess or onQueryFailed, it says Access denied on SP_ClientRuntimeContext$executeQueryAsync, sp.runtime.debug.js, line 3103

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

You actually need to generate a SP.ClientContext for the app web and a SP.AppContextSite for the host web. To get a reference to a list in the host web, try the following:

// Get the ClientContext for the app web
clientContext = new SP.ClientContext.get_current();
// Use the host web URL to get a parent context - this allows us to get data from the parent
hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
parentCtx = new SP.AppContextSite(clientContext, hostweburl);
parentWeb = parentCtx.get_web();
parentList = parentWeb.get_lists().getByTitle("SliderList");
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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