How do I get list properties like BaseTemplate, ItemCount, ListItemDeletedDate etc. via Javascript Client Object Model for SharePoint 2013?
2 Answers
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>
-
1here's rest of properties if you need, msdn.microsoft.com/en-us/library/ee547487(v=office.14).aspx Commented Apr 16, 2013 at 8:39
-
@ameliapond This was 4 years ago. I don't recall how I got it to work. All I do remember is that, that snippet only pointed me in the direction I needed.– user2536Commented Feb 15, 2017 at 7:52
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.
-
Thank you for this. I actually need this for another project.– user2536Commented Apr 16, 2013 at 8:47