Manage Learn to apply best practices and optimize your operations.

Get names from nested NAB groups

A simple LotusScript agent using recursion can very easily explode groups to any depth.

I've seen many applications that make use of NAB groups to populate choice lists, etc. However, if groups are nested to any level, I challenge anyone to return a fully exploded list using simple @Functions. A simple LotusScript agent using recursion can very easily explode groups to any depth.

The key function in the code below is ExplodeIt(). The other code is included to make a working example. Try stepping through it with the debugger, and change GroupName$ to something meaningful for your environment. The end result is array PeopleNames(), sorted into alphabetical order, with any duplicates removed.

Note - I take no credit for function SortArray() which I got from this or a similar 'tips' database.


'Explode Group Name: 

Option Public

Dim PeopleNames()
Dim db As NotesDatabase
Dim NAB As NotesDatabase
Dim NABView As NotesView

Sub Initialize
     Dim s As New NotesSession
     Set db = s.currentdatabase
     Redim Preserve PeopleNames(0)
     Set NAB = New NotesDatabase( db.server , "NAMES.NSF")
     Set NABView = NAB.GetView( "Groups" )
     
     GroupName$ = "AnyGroup in NAB"
     
     Call ExplodeIt( GroupName$ )     
     
     Call SortArray( PeopleNames )
     Call FilterArray( PeopleNames )
End Sub


Function ExplodeIt( item )
     Dim GroupDoc As NotesDocument
     Set GroupDoc  = NABView.GetDocumentByKey( item , exact )
     If GroupDoc Is Nothing Then
          Call AddToList ( item )
     Else
          Forall item2 In GroupDoc.members
               Call ExplodeIt( item2 )
          End Forall
     End If
     
End Function
Function AddToList( item )
     PeopleNames(Ubound( PeopleNames) ) = item
     Redim  Preserve PeopleNames( Ubound(PeopleNames) + 1)
     
End Function
Sub SortArray(work)
     
     i% = -1
     Forall stringItem In work          
          i% = i% + 1
          minS$ = stringItem
          minJ% = i%
          For j% = i% To Ubound(work)
               If work(j%) < minS$ Then
                    minS$ = work(j%)
                    minJ% = j%
               End If
          Next
          If i% <> minJ% Then   'Last item, no need to exchange
               work(minJ%) = work(i%)
               work(i%) = minS$
          End If
     End Forall
     
End Sub

Function FilterArray( work )
     Dim tmparray()
     Dim counter%
     Dim lastvalue
     Dim curvalue
     lastvalue = ""
     Redim Preserve tmparray( 0 )
     For counter% = 0 To Ubound( work ) 
          curvalue = work( counter% )
          If curvalue <> lastvalue Then
               tmparray( Ubound( tmparray )) = curvalue
               Redim Preserve tmparray( Ubound(tmparray) + 1)
               lastvalue = curvalue
          End If
     Next
     ' tmparray will have one extra element so redim to remove it
     If Ubound(tmparray) > 0 Then
          Redim Preserve tmparray( Ubound( tmparray ) -1)
     End If
     Redim work(Ubound (tmparray))
     For counter% = 0 To Ubound(tmparray)
          work( counter%) = tmparray( counter% )
     Next
     FilterArray = work
End Function

1

Dig Deeper on Domino Resources - Part 7

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close