4

I want to get the row count of a list using JSOM but I am not able to get it.

Can any one help ?

The code am using is as below:

 function retrieveBookingDetails(BDate) {   
     var ctx = new SP.ClientContext(appWebUrl);//Get the SharePoint Context object based upon the URL
        var myList = ctx.get_web().get_lists().getByTitle("MyList");
        var query = new SP.CamlQuery();
        query.set_viewXml('<View><Where><eq><FieldRef Name=\'EventDate\'/><Value Type=\'DateTime\'IncludeTimeValue=\'FALSE\' >' + BDate + '</Value></eq>" + "</Where></View>');
        var items = myList.getItems(query);
        ctx.load(items);
        ctx.executeQueryAsync(onQuerySucceeded, onQueryFailed);
        function onQuerySucceeded() {
            retrieveItems(items);
        }
        function onQueryFailed(sender, args) {
            alert('Request failed. ' + args.get_message() +
                '\n' + args.get_stackTrace());
        }
    function retrieveItems(items) {
        var enumerator = items.getEnumerator();      
        var count = 0;
        var count = items.get_count();           
        while (enumerator.moveNext()) {    
     //am generating HTML here
    }
}
5
  • 1
    Show your code? Aug 29, 2016 at 9:21
  • myList.get_itemCount(); will give you total items/rows in the list. items.get_count() will give you total items/rows returned by your CAML query Aug 29, 2016 at 10:06
  • what if i want to display all events of single date in single row of html table in <td></td>?
    – Madhav
    Aug 29, 2016 at 11:09
  • It's a different question. So you better ask another question. I will try to help. :) Aug 29, 2016 at 11:11
  • pl;ease check this question sharepoint.stackexchange.com/questions/192144/…
    – Madhav
    Aug 29, 2016 at 11:18

1 Answer 1

3

Should you try to use the get_count() function for list items as the following

 var count = 0;
    var count = listItems.get_count();

Also check MSDN to Gets a value that specifies the number of list items in the list as

var value = myList.get_itemCount(); 

[Update]

Should you check a similar scenario at Get Current Event Count

9
  • am already using this but it gives me the count of items rather count of rows
    – Madhav
    Aug 29, 2016 at 9:20
  • sorry here i forgot to mention one thing the list is a calendar list
    – Madhav
    Aug 29, 2016 at 9:22
  • No problem also set your code please Aug 29, 2016 at 9:22
  • now check the question i have updated that with my code
    – Madhav
    Aug 29, 2016 at 9:34
  • Dear @Ma6139735 are you tried myList.get_itemCount() Aug 29, 2016 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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