2

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?

simon peter
  • 403
  • 8
  • 19

2 Answers2

5

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.

Serdar Basegmez
  • 3,355
  • 16
  • 20
  • Thanks for your post, but i need to return the ground total of a particular category base on the document opened and not all category – simon peter Aug 04 '14 at 09:28
  • 1
    The same idea applies. You can navigate categories by this loop and get what you want. Did I misundertand your question? Maybe you should give an example on that. – Serdar Basegmez Aug 04 '14 at 09:32
  • the view is a response document why the category is the parent document Id, so i want when parent document is open my computed field should return the ground total of the response relating to him. – simon peter Aug 04 '14 at 09:37
1
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();
  • You can use the in built lotus script function for doing the sum, all you need to do is to specify the column as you can see in the code above. – Samuel Omopariola Jun 09 '16 at 13:07