Facing Error Unable to Get List,Please Help Me currently tying to create SharePoint Hosted App(Image Slide) on my AppDev Site https://akki.sharepoint.com/sites/appdev

I have Created Picture Library on above site with name "Image Slider"

Using Napa tool Created project "Picture Slider"

inside APP.js write Some Logic s as follow

'use strict';
var siteUrl="http://akki.com/sites/AppDev";

var context = new SP.ClientContext.get_current();// (siteUrl);

//var user = context.get_web().get_currentUser();

var libraryName ="Image Slider";
var libraries;
var items;

(function () {

$(document).ready(function () {


function loadSharePointPictures() {

  // var context = new SP.ClientContext.get_current();

     var web = context.get_web();

     libraries = web.get_lists(); 


//check whether list is exist or not  
 function IsListExist() {  
  //alert('check whether list is exist or not');  
  var isListAvail = false;  
  var listEnumerator = libraries.getEnumerator();  
  while (listEnumerator.moveNext()) {  
  var currentlibrary = listEnumerator.get_current();  
 //check whether the library name is equal to current library   
if (currentlibrary.get_title() == libraryName) {  
isListAvail = true;  
//Retrieve list items from the lists  
if (!isListAvail) {  
    alert('Image Slider Picture Library is not available in this site');  


function errorFunction(){

//Get image collection from Library  
function getListItemCollection() {
var library=libraries.getByTitle(libraryName);
var CamelQuery=new SP.CamlQuery();
                        "<Where>" +
                        "<IsNotNull>" +
                        "<FieldRef Name='EncodedAbsUrl' />" +
                        "</IsNotNull>" +



 //Get Image name from Library  
   function OnGetListItemSuccess() { 
      var enumarator=items.getEnumerator();
      while (enumarator.moveNext())
        var CurrentListItem=enumarator.get_current();
        var imagePath=CurrentListItem.get_item("EncodedAbsUrl");
        var link=CurrentListItem.get_item("URL");

    //Create Html div tag    
         var div = document.createElement("div");
         var itemClass=document.createAttribute("class"); 

         //Create Html anchor tag

         var anchor=document.createElement("anchor");
         var href=document.createAttribute("href");

         //Create Html image tag
         var image=document.createElement("image");
         var src=document.createAttribute("src");

         //Append Elements

 function OnGetListItemFailure(sender, args) {  
 alert('Failed to get Items. Error:' + args.get_message());  

Facing Error Unable to Get List,Please Help Me

1 Answer 1


After lots of research found Artical SharePoint App accessing data from host web

Its Working For Me

SharePoint App accessing data from host web The SharePoint app can access the host web by using the standard provided SharePoint web services. When the App first launches, SharePoint provides three values in the query string named: SPHostUrl, SPAppWebUrl and SPLanguage.

By using the first two we can use a JavaScript to access the host web services. The only thing to get this working is to ask the app installer to provide the permissions.

These App permissions can be set in the AppManifest.xml, using the provided editor in Visual Studio 2012. When the permissions are set, please do only ask for permissions you really need.


After a user installed the App, the user will be asked to trust the App. If the user decide not to trust the App, the App will still be installed and users can launch the App. This results in a permissions issue which must be dealt with when the App wants to access the resources.

​When the correct permission requests are set, we can use the SPHostUrl and SPAppWebUrl to connect to the SharePoint web services. This code snipit below gets the query parameters and loads the necessary SharePoint JavaScript files.

  var web;
  var hostweburl;
  var appweburl;

   function sharePointReady() {
   hostweburl =
     appweburl =

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

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

     function getQueryStringParameter(param) {
      var params = document.URL.split("?")[1].split("&");
     var strParams = "";
    for (var i = 0; i < params.length; i = i + 1) {
     var singleParam = params[i].split("=");
    if (singleParam[0] == param) {
    return singleParam[1];
  After the SharePoint JavaScript files are loaded, the appweburl is needed to create a context. With this context we can create a appContextSite to get to the host web. After this its all oldschool JSOM.

     function printAllListNamesFromHostWeb() {
    var context;
    var factory;
    var appContextSite;
   var collList;

  context = new SP.ClientContext(appweburl);
  factory = new SP.ProxyWebRequestExecutorFactory(appweburl);
  appContextSite = new SP.AppContextSite(context, hostweburl);

  this.web = appContextSite.get_web();
  collList = this.web.get_lists();

  Function.createDelegate(this, successHandler),
  Function.createDelegate(this, errorHandler)

  function successHandler() {
  var listInfo = '';
  var listEnumerator = collList.getEnumerator();

  while (listEnumerator.moveNext()) {
    var oList = listEnumerator.get_current();
    listInfo += '<li>' + oList.get_title() + '</li>';

  document.getElementById("message").innerHTML = 'Lists found:<ul>' +            listInfo + '</ul>';

   function errorHandler(sender, args) {
   document.getElementById("message").innerText =
    "Could not complete cross-domain call: " + args.get_message();

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.