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.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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 Sherwin Cancel reply