9/14/2010

Getting your sub-categories right

Do you need to get Data from a specific subcategory in x-pages?

Maybe, you want to use categories to get totals easy and precalculated like this:

You have a view with three categories:
Column 1: Category 1 ("Year")
Column 2: Category 2 ("Customer")
Column 3: Category 3 ("Month(s)")
Column 4,5: some totals for each month

You want to get a specific Category 2, and output alls the stats it has in the Category3...

You could be trying to use a the following code:
viewNav = view1.createViewNavFromCategory("Cat1\\Cat2")

But: until now, it returns only the complete first category "Cat1" in the navigator - well need "Cat2"

The help states explicitly:

createViewNavFromCategory(string):
Creates a view navigator for all entries in a view under a specified category. [..]
-->Subcategories can be specified using backslash notation (don't forget to escape the backslashes), for example, "Asia\\Korea" means the subcategory "Korea" under the main category "Asia."
[..]

But - it does not work yet, maybe it will in 8.5.2 (Lotus Notes 8.5 Forum Post).
Soo... until then, you have to use the following code to get to the category you actually want to use:

var viewEnt:NotesViewEntry = viewNav.getFirst();
// skip the categories we dont need
while(viewEnt!=null && !(viewEnt.getColumnValues().size()>1&&viewEnt.getColumnValues()[1]==variableWithMyWantedCategory2Name))
    viewEnt=viewNav.getNextCategory();
//now were there, dive into this category
viewEnt=viewNav.getNextCategory();
// it also seems to have all following categories... so exit the loop, when we arrive on the next higher category
 while (viewEnt != null&&viewEnt.getIndentLevel()>1) {
     //actual code goes here: output totals for use e.g. in a report
    viewEnt=viewNav.getNextCategory();
}

Here is another workaround, kindly provided by Tommy Valand (very appreciated):

While NotesView.createViewNavFromCategory is broken:
  • create a flat lookup view with all the "category keys" in the first column (separated by any non-subcategory marker,e.g. / or |)
  • then use
    NotesView.getAllEntriesByKey( partialCategoryKey, false )
  • The option false will partially match all the "subcategory" entries.

No comments:

Post a Comment