locked
client Side object model calling two functions RRS feed

  • Question

  • Hi,

    Here is my use case. I have case, where I make a JSOM call to return some fields from a list and then I need to use one of these returned fields as argument and make another JSOM call. Below is the script I tried. I pass a field into getStatus function but my second JSOM call returns an error:

    Uncaught Error: The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.

    Script

    var roadmapList;
    var collListItem;
    var dashboardList;
    var statusItem;

    ExecuteOrDelayUntilScriptLoaded(loadRoadMap, "sp.js");

    function loadRoadMap()
    {

        var currentCtx = SP.ClientContext.get_current();
        var currentWeb = currentCtx.get_web();
        this.roadmapList = currentWeb.get_lists().getByTitle('Roadmap');
        var camlQuery = new SP.CamlQuery();
        this.collListItem = roadmapList.getItems(camlQuery);
        currentCtx.load(collListItem);
        currentCtx.executeQueryAsync(
            Function.createDelegate(this, this.onQuerySucceeded),
            Function.createDelegate(this, this.onQueryFailed)
        );

    }

    function onQuerySucceeded(sender, args) {
        var listItemInfo = '';
        var listItemEnumerator = collListItem.getEnumerator();

        while (listItemEnumerator.moveNext()) {
            //alert("Success");
            var oListItem = listItemEnumerator.get_current();
            var projectUrl = oListItem.get_item('ProjectURL').get_url();
            listItemInfo += '<tr><td>' + oListItem.get_item('Roadmap_x0020_Project') + '</td><td>' + getStatus(projectUrl) + '</td></tr>';
            $('#statusTable').append($(listItemInfo));
        }
        
    }

    function onQueryFailed(sender, args) {
        alert('Request failed. ' + args.get_message() +
            '\n' + args.get_stackTrace());
    }


    function getStatus(project) {
        var crossSiteContext = new SP.ClientContext("http://myanothersite.com/it/");
        var crossSiteWeb = crossSiteContext.get_web();
        this.dashboardList = crossSiteWeb.get_lists().getByTitle('Dashboard');
        var projectQuery = new SP.CamlQuery();
        
        projectQuery.set_viewXml("<View><Query><Where><Eq><FieldRef Name=\'Project\'/>" + 
            "<Value Type=\'URL\'>"+ project +"</Value></Eq></Where></Query>" + 
            "<RowLimit>1000</RowLimit></View>");
        this.statusItem = dashboardList.getItems(projectQuery);
        crossSiteContext.load(statusItem);
        crossSiteContext.executeQueryAsync(
            Function.createDelegate(this,  this.onStatusQuerySucceeded),
            Function.createDelegate(this,  this.onStatusQueryFailed)
            );

    }


    function onStatusQuerySucceeded(sender, args) {
        var projectItemInfo = '';
        var projectItemEnumerator = statusItem.getEnumerator();

        while (projectItemEnumerator.moveNext())
        {
            var curstatusItem = projectItemEnumerator.get_current();
            projectItemInfo += '\nID: ' + curstatusItem.get_id() +
                '\nStatus: ' + curstatusItem.get_item('Project_x0020_Status').Label;
          }
     
    }


    function onStatusQueryFailed(sender, args) {
        alert('Request failed. ' + args.get_message() +
           '\n' + args.get_stackTrace());
    }

    Saturday, November 1, 2014 3:58 PM

Answers

  • Hi,

    In SharePoint 2013, we can use REST API + jQuery Ajax to achieve your requirement.

    JQuery Ajax provide synchronous call(async:false) to do this.

    Web API With AJAX: Understand Synchronous and Asynchronous Call in jQuery ajax Method

    http://www.c-sharpcorner.com/UploadFile/dacca2/web-api-with-ajax-understand-synchronous-and-asynchronous-c/

    SharePoint 2013 – CRUD on List Items Using REST Services & jQuery

    http://www.plusconsulting.com/blog/2013/05/crud-on-list-items-using-rest-services-jquery/

    Thanks,
    Dennis Guo
    TechNet Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Dennis Guo
    TechNet Community Support

    • Marked as answer by Patrick_Liang Thursday, November 13, 2014 2:01 AM
    Monday, November 3, 2014 2:08 AM
  • Hi,

    SharePoint JavaScript client object model is asynchronous. To process the data in synchronous model, you have to use one of JavaScript synchronizing technique such as Callbacks or Promises.  For more details how to use this technique, please refer to the following article.

    http://www.sharepointnadeem.com/2014/10/sharepoint-using-deferredspromises-or.html

    Some of the browsers such IE does not support Promises, so you have to use Callback technique.

    var roadmapList;
    var collListItem;
    var dashboardList;
    var statusItem;
    
    ExecuteOrDelayUntilScriptLoaded(loadRoadMap, "sp.js");
    
    function loadRoadMap() {
    
      var currentCtx = SP.ClientContext.get_current();
      var currentWeb = currentCtx.get_web();
      this.roadmapList = currentWeb.get_lists().getByTitle('Roadmap');
      var camlQuery = new SP.CamlQuery();
      this.collListItem = roadmapList.getItems(camlQuery);
      currentCtx.load(collListItem);
      currentCtx.executeQueryAsync(
        Function.createDelegate(this, this.onQuerySucceeded),
        Function.createDelegate(this, this.onQueryFailed)
      );
    
    }
    
    function onQuerySucceeded(sender, args) {
      var listItemInfo = '';
      var listItemEnumerator = collListItem.getEnumerator();
    
      while (listItemEnumerator.moveNext()) {
        //alert("Success");
        var oListItem = listItemEnumerator.get_current();
        var projectUrl = oListItem.get_item('ProjectURL').get_url();
        listItemInfo += '<tr><td>' + oListItem.get_item('Roadmap_x0020_Project') + '</td>';
        $('#statusTable').append($(listItemInfo));
    
        //Callback function
        getStatus(projectUrl, function(projectItems) {
            var projectItemInfo = '';
            var projectItemEnumerator = projectItems.getEnumerator();
    
            while (projectItemEnumerator.moveNext()) {
              var curstatusItem = projectItemEnumerator.get_current();
              projectItemInfo += '<td>' + 'ID: ' + curstatusItem.get_id() + 'Status: ' + 
              curstatusItem.get_item('Project_x0020_Status').Label + '</td></tr>';
              $('#statusTable').append($(projectItemInfo));
            }
          },
          function(sender, args) {
            console.log('An error occured while retrieving list items:' + args.get_message());
          }
        );
    
      }
    }
    
    function onQueryFailed(sender, args) {
      alert('Request failed. ' + args.get_message() +
        '\n' + args.get_stackTrace());
    }
    
    
    function getStatus(project, success, error) {
      var crossSiteContext = new SP.ClientContext("http://myanothersite.com/it/");
      var crossSiteWeb = crossSiteContext.get_web();
      this.dashboardList = crossSiteWeb.get_lists().getByTitle('Dashboard');
      var projectQuery = new SP.CamlQuery();
    
      projectQuery.set_viewXml("<View><Query><Where><Eq><FieldRef Name=\'Project\'/>" +
        "<Value Type=\'URL\'>" + project + "</Value></Eq></Where></Query>" +
        "<RowLimit>1000</RowLimit></View>");
      this.statusItem = dashboardList.getItems(projectQuery);
      crossSiteContext.load(statusItem);
    
      crossSiteContext.executeQueryAsync(
        function() {
          success(projectItems);
        },
        error
      );
    }

    I have not tested this code, please test and make necessary changes if any errors occurred.

    Please mark it as answered, if your problem resolved or helpful.

    • Marked as answer by Patrick_Liang Thursday, November 13, 2014 2:01 AM
    Saturday, November 1, 2014 5:41 PM
  • I see that many people struggling with understanding how to build async driven code.

    function getData(){
    
      dfd = new $.Deferred()
    
     
    $.ajax({
      type: "GET",
      url: "test.js",
    
      success:function(data){
    
    	dfd.resolve(data);
    
      }
    
    });
    
    
       return dfd.promise()
    
    }
    
    
    
    getData().then(function(data){
    
    //your second call
    
    });


     
    • Marked as answer by Patrick_Liang Thursday, November 13, 2014 2:01 AM
    Monday, November 3, 2014 4:03 AM

All replies

  • Hi,

    SharePoint JavaScript client object model is asynchronous. To process the data in synchronous model, you have to use one of JavaScript synchronizing technique such as Callbacks or Promises.  For more details how to use this technique, please refer to the following article.

    http://www.sharepointnadeem.com/2014/10/sharepoint-using-deferredspromises-or.html

    Some of the browsers such IE does not support Promises, so you have to use Callback technique.

    var roadmapList;
    var collListItem;
    var dashboardList;
    var statusItem;
    
    ExecuteOrDelayUntilScriptLoaded(loadRoadMap, "sp.js");
    
    function loadRoadMap() {
    
      var currentCtx = SP.ClientContext.get_current();
      var currentWeb = currentCtx.get_web();
      this.roadmapList = currentWeb.get_lists().getByTitle('Roadmap');
      var camlQuery = new SP.CamlQuery();
      this.collListItem = roadmapList.getItems(camlQuery);
      currentCtx.load(collListItem);
      currentCtx.executeQueryAsync(
        Function.createDelegate(this, this.onQuerySucceeded),
        Function.createDelegate(this, this.onQueryFailed)
      );
    
    }
    
    function onQuerySucceeded(sender, args) {
      var listItemInfo = '';
      var listItemEnumerator = collListItem.getEnumerator();
    
      while (listItemEnumerator.moveNext()) {
        //alert("Success");
        var oListItem = listItemEnumerator.get_current();
        var projectUrl = oListItem.get_item('ProjectURL').get_url();
        listItemInfo += '<tr><td>' + oListItem.get_item('Roadmap_x0020_Project') + '</td>';
        $('#statusTable').append($(listItemInfo));
    
        //Callback function
        getStatus(projectUrl, function(projectItems) {
            var projectItemInfo = '';
            var projectItemEnumerator = projectItems.getEnumerator();
    
            while (projectItemEnumerator.moveNext()) {
              var curstatusItem = projectItemEnumerator.get_current();
              projectItemInfo += '<td>' + 'ID: ' + curstatusItem.get_id() + 'Status: ' + 
              curstatusItem.get_item('Project_x0020_Status').Label + '</td></tr>';
              $('#statusTable').append($(projectItemInfo));
            }
          },
          function(sender, args) {
            console.log('An error occured while retrieving list items:' + args.get_message());
          }
        );
    
      }
    }
    
    function onQueryFailed(sender, args) {
      alert('Request failed. ' + args.get_message() +
        '\n' + args.get_stackTrace());
    }
    
    
    function getStatus(project, success, error) {
      var crossSiteContext = new SP.ClientContext("http://myanothersite.com/it/");
      var crossSiteWeb = crossSiteContext.get_web();
      this.dashboardList = crossSiteWeb.get_lists().getByTitle('Dashboard');
      var projectQuery = new SP.CamlQuery();
    
      projectQuery.set_viewXml("<View><Query><Where><Eq><FieldRef Name=\'Project\'/>" +
        "<Value Type=\'URL\'>" + project + "</Value></Eq></Where></Query>" +
        "<RowLimit>1000</RowLimit></View>");
      this.statusItem = dashboardList.getItems(projectQuery);
      crossSiteContext.load(statusItem);
    
      crossSiteContext.executeQueryAsync(
        function() {
          success(projectItems);
        },
        error
      );
    }

    I have not tested this code, please test and make necessary changes if any errors occurred.

    Please mark it as answered, if your problem resolved or helpful.

    • Marked as answer by Patrick_Liang Thursday, November 13, 2014 2:01 AM
    Saturday, November 1, 2014 5:41 PM
  • Hi Mokhtar,

    I am having hard time following your code. Can you please explain each function?

    Thanks

    Saturday, November 1, 2014 6:35 PM
  • Hi,

    The callback function is as follows getStatus(projectUrl,<<dynamic function - function(projectItems)>>,<<dynamic function - error handler>>);

    //Callback function
        getStatus(projectUrl, function(projectItems) {
            var projectItemInfo = '';
            var projectItemEnumerator = projectItems.getEnumerator();
    
            while (projectItemEnumerator.moveNext()) {
              var curstatusItem = projectItemEnumerator.get_current();
              projectItemInfo += '<td>' + 'ID: ' + curstatusItem.get_id() + 'Status: ' + 
              curstatusItem.get_item('Project_x0020_Status').Label + '</td></tr>';
              $('#statusTable').append($(projectItemInfo));
            }
          },
          function(sender, args) {
            console.log('An error occured while retrieving list items:' + args.get_message());
          }
        );

    The above function calls the below function and wait for the execution to be completed before proceeding. The "success" and "error" parameters are function parameters which will have dynamic functions

    function getStatus(project, success, error) {
      var crossSiteContext = new SP.ClientContext("http://myanothersite.com/it/");
      var crossSiteWeb = crossSiteContext.get_web();
      this.dashboardList = crossSiteWeb.get_lists().getByTitle('Dashboard');
      var projectQuery = new SP.CamlQuery();
    
      projectQuery.set_viewXml("<View><Query><Where><Eq><FieldRef Name=\'Project\'/>" +
        "<Value Type=\'URL\'>" + project + "</Value></Eq></Where></Query>" +
        "<RowLimit>1000</RowLimit></View>");
      this.statusItem = dashboardList.getItems(projectQuery);
      crossSiteContext.load(statusItem);
    
      crossSiteContext.executeQueryAsync(
        function() {
          success(projectItems);
        },
        error
      );
    }

    For more details how callback functionality works...Please refer to the following links.

    http://www.w3schools.com/jquery/jquery_callback.asp

    http://cwbuecheler.com/web/tutorials/2013/javascript-callbacks/

    http://javascriptissexy.com/understand-javascript-callback-functions-and-use-them/

    Please mark it as answered, if your problem resolved or helpful.

    Saturday, November 1, 2014 6:52 PM
  • Sorry I am still confused..So did you use  a different variable called "projectItems" instead of "statusitem"? Can you please use same variable names as I used. For some reason, When I tried,it is not working.
    Sunday, November 2, 2014 2:04 AM
  • here is what I tried:

    var roadmapList;
    var collListItem;
    var dashboardList;
    var statusItem;

    ExecuteOrDelayUntilScriptLoaded(loadRoadMap, "sp.js");

    function loadRoadMap()
    {

        var currentCtx = SP.ClientContext.get_current();
        var currentWeb = currentCtx.get_web();
        this.roadmapList = currentWeb.get_lists().getByTitle('Roadmap');
        var camlQuery = new SP.CamlQuery();
        this.collListItem = roadmapList.getItems(camlQuery);
        currentCtx.load(collListItem);
        currentCtx.executeQueryAsync(
            Function.createDelegate(this, this.onQuerySucceeded),
            Function.createDelegate(this, this.onQueryFailed)
        );

    }

    function onQuerySucceeded(sender, args) {
        var listItemInfo = '';
        var listItemEnumerator = collListItem.getEnumerator();

        while (listItemEnumerator.moveNext()) {
            //alert("Success");
            var oListItem = listItemEnumerator.get_current();
            var projectUrl = oListItem.get_item('ProjectURL').get_url();
            listItemInfo += '<tr><td>' + oListItem.get_item('Roadmap_x0020_Project') + '</td><td>' +  getStatus(projectUrl, function(projectItems) {
            var projectItemInfo = '';
            var projectItemEnumerator = projectItems.getEnumerator();

            while (projectItemEnumerator.moveNext()) {
              var curstatusItem = projectItemEnumerator.get_current();
              projectItemInfo += '<td>' + 'ID: ' + curstatusItem.get_id() + 'Status: ' + 
              curstatusItem.get_item('Project_x0020_Status').Label + '</td></tr>';
              $('#statusTable').append($(projectItemInfo));
            }
          },
          function(sender, args) {
            alert('An error occured while retrieving list items:' + args.get_message());
          }
        ) + '</td></tr>';
            $('#statusTable').append($(listItemInfo));
        }
        
    }

    function onQueryFailed(sender, args) {
        alert('Request failed. ' + args.get_message() +
            '\n' + args.get_stackTrace());
    }


    function getStatus(project, success, error) {
        var crossSiteContext = new SP.ClientContext("http://mytestsite.com/it/");
        var crossSiteWeb = crossSiteContext.get_web();
        this.dashboardList = crossSiteWeb.get_lists().getByTitle('Dashboard');
        var projectQuery = new SP.CamlQuery();
        
        projectQuery.set_viewXml("<View><Query><Where><Eq><FieldRef Name=\'Project\'/>" + 
            "<Value Type=\'URL\'>"+ project +"</Value></Eq></Where></Query>" + 
            "<RowLimit>1000</RowLimit></View>");
        this.statusItem = dashboardList.getItems(projectQuery);
        crossSiteContext.load(statusItem);
        crossSiteContext.executeQueryAsync(
            function(){
                success(statusItem)
            },

            error
            
            
            );

    }

    I am getting "undefined" values for status column basically nothing is being returned.

    Sunday, November 2, 2014 2:33 AM
  • Hi,

    Here is my use case. I have case, where I make a JSOM call to return some fields from a list and then I need to use one of these returned fields as argument and make another JSOM call. Below is the script I tried. I pass a field into getStatus function but my second JSOM call returns an error:

    Uncaught Error: The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.

    Script

    var roadmapList;
    var collListItem;
    var dashboardList;
    var statusItem;

    ExecuteOrDelayUntilScriptLoaded(loadRoadMap, "sp.js");

    function loadRoadMap()
    {

        var currentCtx = SP.ClientContext.get_current();
        var currentWeb = currentCtx.get_web();
        this.roadmapList = currentWeb.get_lists().getByTitle('Roadmap');
        var camlQuery = new SP.CamlQuery();
        this.collListItem = roadmapList.getItems(camlQuery);
        currentCtx.load(collListItem);
        currentCtx.executeQueryAsync(
            Function.createDelegate(this, this.onQuerySucceeded),
            Function.createDelegate(this, this.onQueryFailed)
        );

    }

    function onQuerySucceeded(sender, args) {
        var listItemInfo = '';
        var listItemEnumerator = collListItem.getEnumerator();

        while (listItemEnumerator.moveNext()) {
            //alert("Success");
            var oListItem = listItemEnumerator.get_current();
            var projectUrl = oListItem.get_item('ProjectURL').get_url();
            listItemInfo += '<tr><td>' + oListItem.get_item('Roadmap_x0020_Project') + '</td><td>' + getStatus(projectUrl) + '</td></tr>';
            $('#statusTable').append($(listItemInfo));
        }
        
    }

    function onQueryFailed(sender, args) {
        alert('Request failed. ' + args.get_message() +
            '\n' + args.get_stackTrace());
    }


    function getStatus(project) {
        var crossSiteContext = new SP.ClientContext("http://myanothersite.com/it/");
        var crossSiteWeb = crossSiteContext.get_web();
        this.dashboardList = crossSiteWeb.get_lists().getByTitle('Dashboard');
        var projectQuery = new SP.CamlQuery();
        
        projectQuery.set_viewXml("<View><Query><Where><Eq><FieldRef Name=\'Project\'/>" + 
            "<Value Type=\'URL\'>"+ project +"</Value></Eq></Where></Query>" + 
            "<RowLimit>1000</RowLimit></View>");
        this.statusItem = dashboardList.getItems(projectQuery);
        crossSiteContext.load(statusItem);
        crossSiteContext.executeQueryAsync(
            Function.createDelegate(this,  this.onStatusQuerySucceeded),
            Function.createDelegate(this,  this.onStatusQueryFailed)
            );

    }


    function onStatusQuerySucceeded(sender, args) {
        var projectItemInfo = '';
        var projectItemEnumerator = statusItem.getEnumerator();

        while (projectItemEnumerator.moveNext())
        {
            var curstatusItem = projectItemEnumerator.get_current();
            projectItemInfo += '\nID: ' + curstatusItem.get_id() +
                '\nStatus: ' + curstatusItem.get_item('Project_x0020_Status').Label;
          }
     
    }


    function onStatusQueryFailed(sender, args) {
        alert('Request failed. ' + args.get_message() +
           '\n' + args.get_stackTrace());
    }
    • Merged by Dennis Guo Monday, November 17, 2014 9:48 AM the same issue
    Monday, November 3, 2014 1:44 AM
  • Hi,

    In SharePoint 2013, we can use REST API + jQuery Ajax to achieve your requirement.

    JQuery Ajax provide synchronous call(async:false) to do this.

    Web API With AJAX: Understand Synchronous and Asynchronous Call in jQuery ajax Method

    http://www.c-sharpcorner.com/UploadFile/dacca2/web-api-with-ajax-understand-synchronous-and-asynchronous-c/

    SharePoint 2013 – CRUD on List Items Using REST Services & jQuery

    http://www.plusconsulting.com/blog/2013/05/crud-on-list-items-using-rest-services-jquery/

    Thanks,
    Dennis Guo
    TechNet Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Dennis Guo
    TechNet Community Support

    • Marked as answer by Patrick_Liang Thursday, November 13, 2014 2:01 AM
    Monday, November 3, 2014 2:08 AM
  • I see that many people struggling with understanding how to build async driven code.

    function getData(){
    
      dfd = new $.Deferred()
    
     
    $.ajax({
      type: "GET",
      url: "test.js",
    
      success:function(data){
    
    	dfd.resolve(data);
    
      }
    
    });
    
    
       return dfd.promise()
    
    }
    
    
    
    getData().then(function(data){
    
    //your second call
    
    });


     
    • Marked as answer by Patrick_Liang Thursday, November 13, 2014 2:01 AM
    Monday, November 3, 2014 4:03 AM
  • I would suggest you to try https://camljs.codeplex.com/

    Its good library which will help you to build a right query. The only thing, when you pass the query dont forget to wrap it inside <view></view> 

    Monday, November 3, 2014 4:07 AM
  • using REST API is not an option for me because, I need to Query data based on a URL field and return taxonomy field data. Both of which are not possible if I use REST API.

    Monday, November 3, 2014 6:30 PM
  • Hi nicksav,

    Thank you for your suggestions:

    Here is what I tried following Jquery deferred example and I called a simple function. However, When I tried this code. I am getting error: "Cannot read Property of  get_current() Undefined"

    <script type="text/javascript">
    ExecuteOrDelayUntilScriptLoaded(getList, "sp.js");

    function getList(name) {
        var d = $.Deferred();

        var clientContext = new SP.ClientContext.get_current(); //this line throws the error mentioned above.
        var list = clientContext.get_web().get_lists().getByTitle(name);
        var camlQuery = new SP.CamlQuery();
        this.collListItem = list.getItems(camlQuery);
        clientContext.load(collListItem);
        

        var o = { d: d, listColl: collListItem };
        clientContext.executeQueryAsync(Function.createDelegate(o, successCallback), Function.createDelegate(o, failCallback));
        return d.promise();
    }

    function successCallback() {
        this.d.resolve(this.listColl);
    }

    function failCallback() {
        this.d.reject("something bad happened");
    }


    var p = getList("RoadMap");

    p.done(function (result) {
        // result is an SP.ListItemCollection because that is what we passed to resolve()!
        var listItemCollection = result;
        var listItemInfo = '';
        var listItemEnumerator = listItemCollection.getEnumerator();
        // do something with the list

        while (listItemEnumerator.moveNext()) {
            var oListItem = listItemEnumerator.get_current();
            listItemInfo += '\nID: ' + oListItem.get_id() +
                '\nTitle: ' + oListItem.get_item('Title');
                
        }

        alert(listItemInfo.toString());
    });
    p.fail(function (result) {
        // result is a string because that is what we passed to reject()!
        var error = result;
        console.log(error);
    });
    </script>
       

    Monday, November 3, 2014 10:26 PM
  • Hi,

    We can also get taxonomy field data using REST API, the following blog for your reference:

    How to filter on a Managed Metadata column via REST in SharePoint 2013

    http://www.cleverworkarounds.com/2013/09/23/how-to-filter-on-a-managed-metadata-column-via-rest-in-sharepoint-2013/

    Thanks,
    Dennis Guo
    TechNet Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Dennis Guo
    TechNet Community Support

    Tuesday, November 4, 2014 1:31 AM
  • Ok, I see what's wrong with your code. 

    Can you grab SPLoader.js file from here and read the article

    http://ioi.solutions/easy-way-get-sharepoint-context/

    The code for you to get list items after:

    function getFileInformation(listid,itemid) {
        var deferred = $.Deferred();
        SpLoader.ready(function () {
            var context = SpLoader.context;
            var list = SpLoader.hostWeb.get_lists().getById(listid);
    
            var camlBuilder = new CamlBuilder();
    
            var itemIds = itemid.split(',');
            var caml = camlBuilder.Where()
         .IntegerField("ID").In(itemIds)
         .ToString();
    
    
            var camlQuery = new SP.CamlQuery();
            camlQuery.set_viewXml("<View><Query>" + caml + "</Query></View>");
            var collListItem = list.getItems(camlQuery);
    
            context.load(collListItem);
    
    
            context.executeQueryAsync(function () {
                var listItemsFound = [];
                var listItemEnumerator = collListItem.getEnumerator();
    
                while (listItemEnumerator.moveNext()) {
                    var listItem = listItemEnumerator.get_current();
                    var materialRecord = getMaterialInfoFromListItem(listItem, null, null);
                    listItemsFound.push(materialRecord);
                }
                deferred.resolve(listItemsFound);
            },
            function (sender, args) {
                console.log("An error occurred when retrieving the site materials");
                console.log(args.get_message());
                deferred.resolve(args.get_message());
            });
        });
        return deferred.promise();
    }
    

    That SPLoader file will save you tons of your time. 

    And, take to consideration advice from Dennis, REST faster and easiest way to get data.

    Nick

    Wednesday, November 5, 2014 12:26 AM