Today I will share a short script for getting totals from a list view in SharePoint. Imagine this scenario: you have set up a list view with totals and you want get the totals every day for statistics or some other reasons. Instead of getting all items, and/or fiddling around with CamlQueries, there is a better and quicker way - List.RenderListData. This combined with a tip from Piyush K Singhs blog post Get Aggregate Values… I came up with an idea to read the ViewXml from an existing view and retrieve the totals (in my case Count and Sum). Enough talking, let’s take a look at the code:
The good part of that approach is that you can let your view evolve over time and work together with colleagues on that, your script does not need an update every time you change the view. The only thing it alters is the RowLimit - that’s for better performance. Why load 30 or more list items when 1 is enough.
I have tested it in SharePoint 2013 and SharePoint Online.
sam - May 4, 2021
Hi Anatoly. Seems lines 15 and 16 for count and size sum are no longer returning any values in SPO?
Hi Sam, that’s unfortunate. I am not able to check this right now. Please provide your insights if you find a solution.