Support for aggregations in the CAML query builder
CAML queries have built in support for aggregations, which avoids the need to create a javascript function for doing this.
It seems that the CAML query builder ignores the aggregations, though.
This is within a "@Functions.GetFirstValueForQuery". It returns the value of the first list item, not the aggregation.
For example:
<View Scope="Recursive">
<Query>
<Where>
...
</Where>
</Query>
<Aggregations Value="On">
<FieldRef Name="InvoiceAmount" Type="Sum" />
</Aggregations>
<ViewFields>
<FieldRef Name="InvoiceAmount" />
</ViewFields>
</View>
1
-
As a workaround - and for anyone else viewing this - I am doing the SUM calculation as follows:
let invoiceAmounts = [[@Functions.GetValuesForQuery('Lists/Invoices', '<View><Query><Where>...</Where></Query><ViewFields><FieldRef Name="InvoiceAmount" /></ViewFields><RowLimit Paged="TRUE">20</RowLimit></View >', 'InvoiceAmount')]];
const sum = invoiceAmounts.reduce((partialSum, a) => partialSum + a, 0);return sum;1
Please sign in to leave a comment.
Comments
1 comment