3

I want to get the item count of a list, so my code looks like this:

var list = context.get_web().get_lists().getByTitle("tasks");
context.load(list);

Doesn't this way retrieve all properties for the list which is unneeded? How can I know the list of properties each object in SharePoint has in order to be able to do something like: context.load(list,"ItemCount") for example?

Is there a reference for properties of each object in SharePoint or a way to know these attributes as from what I know using load() doesn't get ALL properties by default

4 Answers 4

5

When you only do context.load(list) it retrieves a set of properties as you said. And not all. The list of properties that are available for each class can be found in the documentation from Microsoft which is available here: https://msdn.microsoft.com/en-us/library/office/jj193038.aspx

In the case of a list you'll find all the properties that you can retrieve here: https://msdn.microsoft.com/EN-US/library/office/jj245887.aspx and one of the properties is "itemCount" which can be retrieved by doing context.load(list, "itemCount")

Hope this helps you

0
1

Using SharePoint Plus:

$SP().list("List Name").get({fields:"ID"}, function(data) {
  alert("Number of items: "+data.length)
})

Reference: http://aymkdn.github.io/SharepointPlus/

1
  • 1
    alternate approach always count +1
    – Taran Goel
    Dec 14, 2015 at 12:13
0

To answer your last question, these are the properties that are not automatically retrieved through the Client Object Model (if someone can better format this, please do): : - ContentTypeOrder - UniqueContentTypeOrder

  • List:
    • BrowserFileHandling
    • DataSource
    • EffectiveBasePermissions
    • HasUniqueRoleAssignments
    • IsSiteAssetsLibrary
    • OnQuickLaunch
    • RoleAssignments
    • SchemaXml
    • ValidationFormula
    • ValidationMessage
  • ListItem
    • DisplayName
    • EffectiveBasePermissions
    • HasUniqueRoleAssignments
    • RoleAssignments
  • SecurableObject
    • HasUniqueRoleAssignments
    • RoleAssignments
  • Site
    • Usage
  • Web
    • EffectiveBasePermissions
    • HasUniqueRoleAssignments
    • RoleAssignments

Source: Table 7-1 from Microsoft SharePoint 2013 Developer Reference

-1

Below Call will give you item count of a list.

$.ajax({ 
   url: _spPageContextInfo.webServerRelativeUrl + "/_api/web/lists/getbytitle('NameOfList')/items", 
   type: "GET", 
   headers: {"accept": "application/json;odata=verbose"}, 
   success: function (data) { 

         // TODO: handle the data  
       var itemsCount = data.d.results.length;
         alert(itemsCount); 
   }, 
   error: function (xhr) { 
      alert(xhr.status + ': ' + xhr.statusText); 
   } 
}); 
2
  • 1
    That does not answer the question, I am using csom not rest, and you didn't answer my other questions.. Dec 14, 2015 at 12:10
  • lolz...Ok bro :)
    – Taran Goel
    Dec 14, 2015 at 12:11

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.