Expanding Group Names for Lotus Domino using LotusScript

I needed to find the people that belonged to a given lotus Notes group. It couldn’t be a simple lookup since other groups can and frequently are also members of a group, so it needed to be be recursive.


Function expandGroupListMembers(GroupName) As Variant
 Dim session As New NotesSession
 Dim db As NotesDatabase
 Dim gView As NotesView
 Dim memberList As Variant
 Dim gDoc As NotesDocument

 Set db = session.CurrentDatabase
 Dim nab As New NotesDatabase(db.Server ,"names.nsf") ' this assumes that db is NOT running locally but is a server

 Set gView = nab.GetView("($VIMGroups)" )
 Set gDoc = gView.GetDocumentByKey( GroupName , True )

 If gDoc Is Nothing Then Exit Function 'could not find this GroupName in view so stop and return empty

  memberList = gDoc.GetItemValue( "Members" )
  Forall member In memberList
   Dim subMemberList As Variant
   subMemberList = expandGroupListMembers(member) 'see if member is a group and if so get its members, recursively.
   If Not Isempty(subMemberList) Then
    'member was a group, now add all its members to list
    If Isempty (expandGroupListMembers) Then
     expandGroupListMembers= subMemberList
    Else
     expandGroupListMembers=  AddArraysEval (expandGroupListMembers, subMemberList)
    End If
   Else
    'member was not a group therefore assume is a person and add to list
    ' note it could be a server or something else
    If Isempty (expandGroupListMembers) Then
     expandGroupListMembers= member
    Else
     expandGroupListMembers=  AddArraysEval (expandGroupListMembers, member)
   End If
  End If
  End Forall
 End If
End Function

Function AddArraysEval (a1 As Variant, a2 As Variant) As Variant
 'from http://www.nsftools.com/tools/lsbook.htm
 '** add two arrays or scalar values using @Functions
 Dim session As New NotesSession
 Dim db As NotesDatabase
 Dim doc As NotesDocument
 Dim var As Variant
 Set db = session.CurrentDatabase
 Set doc = New NotesDocument(db)
 Call doc.ReplaceItemValue("a1", a1)
 Call doc.ReplaceItemValue("a2", a2)
 AddArraysEval = Evaluate("a1 : a2", doc)
 '** clean up the memory we used
 Set doc = Nothing
 Set db = Nothing
End Function

the AddArraysEval is from Julian Robichaux’s very handy LotusScript Book

5 Replies to “Expanding Group Names for Lotus Domino using LotusScript”

  1. The code is looking for the function expandGroupList(). Is this just a typo or that function was left out?

    Ian > typo! Should be fixed. sorry about that, and thanks for the catch.

  2. The line 12 is incorrect : It should read
    Set gDoc = gView.GetDocumentByKey( GroupName , True )

    Since the object is declared as gView and not grpsView.

    The line #22 is incorrect. The variable “expandGroupList” is not defined anywhere. What should be the correct line here? I assume the correct should be “expandGroupListMembers” but I don’t know for sure.

    Do You even try to compile and run the code before publishing? These errors would have been spotted right away in the designer…

    • Thanks for the corrections, Kenneth. I’ve applied them to the code sample.

      The code was adapted from living code, and sometimes bugs creep in the editorial processess.

Leave a Reply to IanCancel reply