createViewNavFromCategory("Cat1\\Cat2") does not work as expected

I encountered a possible issue, but maybe i am missing something:

I have a view with three categories:

Column 1: Category 1

Column 2: Category 2

Column 3: Category 3

Column 4,5: some totals

I am trying to use a the following code:

viewNav = view1.createViewNavFromCategory(“Cat1\Cat2”)

But: it returns only the complete first category “Cat1” in the navigator !?

The help states explicitly:

Lotus Domino Designer XPages Reference > Domino > NotesView

createViewNavFromCategory

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.”

[…]

I have to use the following code to get to the category i actually want to use:

var viewEnt:NotesViewEntry = viewNav.getFirst();

// skip the first entry

while(viewEnt!=null && !(viewEnt.getColumnValues().size()>1&&viewEnt.getColumnValues()[1]==variableWithMyWantedCategoryName))

viewEnt=viewNav.getNextCategory();

//now we are there, go 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

viewEnt=viewNav.getNextCategory();

}

Is this a bug, or am i using it wrong?

Subject: Put all categories in the first column

Try to use one column only for the categories and in this column with add all your categories labels with \ between each value.

Renaud

Subject: Still the same problem

Thank you for this quick answer.

I tried it, it makes the view two columns smaller (nice feature though that i did not use yet), but the function returns the same result, except for one/two less columns in it (i tried to use two first columns together and all three in the same column, all both tries end with the same result).

The problem stays the same in the end: only the first category is selected and returned completely.

I am using 8.5.1 FP3 already btw.

Subject: I have seen this to with other method calls (and XPages)

Seems to be a bug. I know 8.5.2 was supposed to allow this, at least for XPages, however, there seems to be a bug in this code and that won’t get fixed. Maybe an IBMer can chime in here with the status.

Howard

Subject: Workaround / Solution: Use Key Lookup

Here is a solution, credit for it goes to Tommy Valand (http://dontpanic82.blogspot.com/) - thank you very much!

If 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 ) ← false=partially matching all the “subcategory” entries.

Please give me a shout if/when the original funtion is working as expected…

Subject: My workaround

Hi all,

Here is my very quick and dirty solution. It seems to work but I didn’t have views including multiple categories (just category → subcategory → subcategory and so on…) so no guarantees =)

function createViewNavFromCategory(nView: NotesView, category, vEntry: viewEntry) {

//If category is not array split it from string using \\

//Max splits (1000) should be enough

try {category.join("")} catch (notArray) {

	category = category.split("\\\\", 1000);

}



//Create NotesViewNavigator

//If entry is available from it otherwise (first loop) from view root

var vNa: NotesViewNavigator = null;

var tmpVEntry: NotesViewEntry = null;

if (vEntry == null) {

	vNa = nView.createViewNav();

} else {

	vNa = nView.createViewNavFromDescendants(vEntry);

}



//We are at the end of category array so =>

//return NotesViewNavigator created from arrays last value descentants

//Skip this from first run (vEntry == null)

if (vEntry != null) {if (vEntry.getIndentLevel() >= category.length - 1) {

	return vNa;

}}



//Loop to find entry matching with same index array value

vEntry = vNa.getFirst();

while (vEntry != null) {

	if (category[vEntry.getIndentLevel()].equals(vEntry.getColumnValues().get(vEntry.getIndentLevel()))) {break;}

	tmpVEntry = vNa.getNextSibling();

	vEntry.recycle();

	vEntry = tmpVEntry;

}

vNa.recycle();



if (vEntry != null) {

	//All fine this far. Lets look further if we can find right entry

	return createViewNavFromCategory(nView, category, vEntry);

} else {

	//Cannot find NotesViewNavigator for this category.

	//We should return empty navigator to mimic NotesView.createViewNavFromCategory()

	//Null works for me

	return null;

}

}