Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Error Getting All lists from Host Web

$
0
0

Hi All,

I recently decided to try out Office 365 so I could so some testing with SharePoint 2013 apps.  I wanted to create a simple application that would display all lists from a sharepoint site in a drop down list.  Below is my CSOM code and it is throwing an "access denied.  you do not have permission to perform this action or access this resource" error.  Any help or pointers would be greatly appreciated.  This is for a hosted app and not a web part.

'use strict';

var web;
var hostweburl;
var appweburl;


 
// This code runs when the DOM is ready and creates a context object which is 
// needed to use the SharePoint object model
$(document).ready(function () {

    hostweburl =
       decodeURIComponent(
           getQueryStringParameter('SPHostUrl')
   );
    appweburl =
        decodeURIComponent(
            getQueryStringParameter('SPAppWebUrl')
     );

    var scriptbase = hostweburl + '/_layouts/15/';

    $.getScript(scriptbase + 'SP.Runtime.js',
        function () {
            $.getScript(scriptbase + 'SP.js',
                function () { $.getScript(scriptbase + 'SP.RequestExecutor.js', printAllListNamesFromHostWeb); }
            );
        }
    );



});


function getQueryStringParameter(urlParameterKey) {   
    var params = document.URL.split('?')[1].split('&');      
    for (var i = 0; i < params.length; i = i + 1) {   
        var singleParam = params[i].split('=');   
        if (singleParam[0] == urlParameterKey)   
            return decodeURIComponent(singleParam[1]);   
    }   
} 

function printAllListNamesFromHostWeb() {
    var context;
    var collList;

    context = new SP.ClientContext.get_current();
    var parentCtx = new SP.AppContextSite(context, hostweburl);
    var parentWeb = parentCtx.get_web();
    collList = parentWeb.get_lists();
    context.load(collList);

    context.executeQueryAsync(
        Function.createDelegate(this, successHandler),
        Function.createDelegate(this, errorHandler)
    );


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>