3

How do I get list properties like BaseTemplate, ItemCount, ListItemDeletedDate etc. via Javascript Client Object Model for SharePoint 2013?

2 Answers 2

3

Okay, so I got some answers on MSDN which were very helpful.

Here is the code-snippet which helped me:

<script type="text/javascript" src="/_layouts/15/init.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>

<script type="text/ecmascript">
    var customlist ;
    function GetListInformation(listGuid) {
        var clientContext = new SP.ClientContext.get_current();
        var oWebsite = clientContext.get_web();
        customlist = oWebsite.get_lists().getById(listGuid);
        clientContext.load(customlist);
        clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
    }       

    function onQuerySucceeded() {
         alert("Last item deleted time : " + this.customlist.get_lastItemDeletedDate() );
         alert("Base Type ID : " + this.customlist.get_baseType());
         alert("Item Count : " + this.customlist.get_itemCount());

    }

    function onQueryFailed(sender, args) {
        alert(" Failed");
    }       
</script>
2
1

Could you not get your properties using REST? Unfortunately I don't have access to my SharePoint 2013 machine for testing myself, but the URL would be similar to http://'site'/_api/web/lists/getbytitle('listName'). You can play about directly in the browser to see the results. Once you have found the correct REST command, you could then use $.ajax() to call within your javascript.

I've written a blog about cross domain REST calls, that won't have your answer, but you will be able to see how to write a ajax call to rest.

http://cann0nf0dder.wordpress.com/2013/04/14/cross-domain-and-sharepoint-hosted-apps-using-rest/

I hope it helps.

1
  • Thank you for this. I actually need this for another project.
    – user2536
    Commented Apr 16, 2013 at 8:47

Your Answer

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