Reputation: 403
I need to get the total sum of a column the view is categorized based on the document Id. i was able to get the total sum of the entire column with the following code:
var myView:NotesView = database.getView("totalScore")
var nav:NotesViewNavigator = myView.createViewNav();
var entry:NotesViewEntry = nav.getLast();
return entry.getColumnValues()[7];
but i need the total sum of a particular category, how can i get the total for each category?
Upvotes: 2
Views: 1168
Reputation: 153
function getColumnSum(){
try {
var unid = param.documentId;
var columnData = @DbLookup(@DbName(), "totalScore", unid, 8);
//column to be summed: counting from 1 will give you 8 instead of [7];
if(columnData != null){
var columnSum = @Sum(columnData).toFixed(0);
return " " + columnSum;
}else{
return " " + "0";
}
}catch(e){
print(e.toString());
}
}
getColumnSum();
Upvotes: 1
Reputation: 3365
You can get category totals in the same way.
var myView:NotesView = database.getView("totalScore")
var nav:NotesViewNavigator = myView.createViewNav();
// Assuming this is a categorized view, so the first entry is a category
var entry:NotesViewEntry = nav.getFirst();
while (entry!=null) {
// column-zero assumed to be a category
print(entry.getColumnValues()[0] + ": " + entry.getColumnValues()[7]);
var tmpEntry:NotesViewEntry = nav.getNextCategory();
entry.recycle();
entry=tmpEntry;
}
The last element will be the grand total where entry.getColumnValues()[0]
will be empty.
Upvotes: 5