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
56
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 = grpsView.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 (expandGroupList) 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 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

This entry was posted in Code, Lotus Domino, Show-n-Tell+Thursday. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

3 Comments

  1. YoGi
    Posted September 8, 2009 at 11:15 am | Permalink

    What about @UserNamesList?

  2. Posted September 8, 2009 at 11:33 am | Permalink

    @UserNamesList will give you Roles and Groups associated with the user in the ACL, but not all the names in a Group.

  3. Sherwin
    Posted November 23, 2009 at 12:01 am | Permalink

    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.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*
  • Follow

  • Archives (since 2003)

  • Categories

  • Recent Posts

  • Twitter Updates

    • I liked a YouTube video -- Recycle your unwanted electronics - City of Toronto http://youtu.be/91OXkMkesBc?a 13 hours ago
    • I'm organizing and coordinating my Japan Trip with Google Wave. Seeing both the promise and the fail. of the product. 19 hours ago
    • I have failed my saving Throw against Shiny ... I new 32G iPod Touch is on order :) 1 day ago
  • del.icio.us links

  • Flickr

    Hanging Gardens of KensingtonHanging Gardens of KensingtonMore Chocolate CakeMore Chocolate Cake
  •  

    September 2009
    M T W T F S S
    « Aug   Oct »
     123456
    78910111213
    14151617181920
    21222324252627
    282930  
  • Spam Blocked