Problem With Multiple Values in a View
I had a view with several columns that had "Show multiple values as separate entries" selected. Obviously, these columns showed fields with ... wait for it...multiple values. I chose to "Show multiple values ad separate entries" because I wanted the multiple values shown alone, each in its own row. Crazy talk, huh?
Okay, so the view is set up and displaying exactly as I want it to. For example, five documents, two values in the field, show as ten rows. Perfect.
Elsewhere in the application, I had an agent that I wanted to walk the view and get the values. I know, this is revolutionary stuff, eh?
So the agent went something like this...
dim view as Notesview
set view = db.GetView ("myMultiValueView")
dim viewcol as NotesViewCollection
set viewcol = view.AllEntries
dim viewEntry as NotesViewEntry
set viewEntry = viewcol.GetFirstEntry()
While Not (viewEntry is Nothing)
myVal = viewEntry.ColumnValues(8)
set viewEntry = viewcol.GetNextEntry(viewEntry)
Wend
Great, right? Except that "myVal" kept returning just the first value of the multivalue field. If there were two values, and consequently two rows, myVal would return the first value twice. Really infuriating when I knew the code was right. This was pretty simple stuff and was NOT working. A quick check of the help files...everything checks out. My view is good. My code is correct. What's the problem?
Google to the rescue and I found this SPR, which explained that what I was doing was not going to work. But also provided a workaround.
dim view as Notesview
set view = db.GetView ("myMultiValueView")
dim nav as NotesViewNavigator
set nav = view.CreateViewNav
dim viewEntry as NotesViewEntry
set viewEntry = nav.GetFirst
While Not (viewEntry is Nothing)
myVal = viewEntry.ColumnValues(8)
set viewEntry = nav.GetNext(viewEntry)
Wend
Hooray! Success! It would have been nice if this was documented in the help file, but at the end of the day (almost literally), I found the way to make it work. And, as is frequently the case, I'm blogging this mostly for other people to find the answer if they have this same problem (including my future self).
Comments
In your case the "Law of Unintended Consequences" likely had a positive effect on your code
Posted by Devin Olson At 15:59:39 On 21/12/2009 | - Website - |
Posted by Mike Brown At 16:24:11 On 21/12/2009 | - Website - |
Of course my own code is FAR from "pure".
Posted by David Leedy At 16:48:48 On 21/12/2009 | - Website - |
Make a set of documents with several multi-value fields, all text.
Field 1: Red, Green, Blue
Field 2: Me, Myself, I
Field 3: This, That, The Other
Field 4: Apples, Churches, Very Small Rocks
Give them all the same values for Field 1, but randomize the values for fields 2-4
Now create a view that has a column for each of these fields, in order. Set them all to "Show multiple values as separate entries."
On the first column, turn on categorization.
Now look at your view CLOSELY.
If you want to do something really special, try CreateViewNavigatorFromCategory("Red"). Then walk the entries and retrieve the .columnValues.
Discuss.
Posted by Nathan T. Freeman At 19:48:12 On 21/12/2009 | - Website - |
Posted by Kathy Brown At 21:23:33 On 21/12/2009 | - Website - |
Posted by Rob Darwin At 13:36:58 On 29/12/2009 | - Website - |
Posted by Carl H Dreyer At 05:57:27 On 04/06/2010 | - Website - |