Why is my list total showing as “Count= undefined”?
-
30-09-2020 - |
Question
I'm updating a view on an existing list programmatically but I can't get the aggregation to work correctly. I'm setting it as follows (the values are pulled from an xml site definition):
if (AggregationStatus == "On")
{
view.Aggregations = "<FieldRef Name=\"" + AggViewField.Name + "\" Type=\"" + AggViewField.Type + "\"/>";
view.AggregationsStatus = AggregationStatus;
}
... more settings here ...
view.Update();
And if I look at the list with SharePoint Manager I can see the aggregation has been applied as follows:
<Aggregations Value="On">
<FieldRef Name="LinkFilename" Type="Count" />
</Aggregations>
Which looks correct to me, but on the site itself the aggregation shows as "Count= undefined". If I modify the view I can see that the Count total is set for the name column and if I now save the view without changing anything the aggregation works properly, which makes me wonder if the view.Update() isn't doing what I think it is. Do I need to update the list as well? Is there some kind of SP_voodoo required to get an aggregation to work?
Any suggestions gratefully accepted.
This is SharePoint 2013 Enterprise on premises and my solution is using VS 2012
Solution
I was looking for an answer to this today. It appears to work if the type is in capitals.
So use:
<Aggregations Value="On">
<FieldRef Name="LinkFilename" Type="COUNT" />
</Aggregations>
instead of:
<Aggregations Value="On">
<FieldRef Name="LinkFilename" Type="Count" />
</Aggregations>