Learn when you want, where you want with convenient online training courses. Sign up now!
Experts Exchange Solution brought to you by
"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.
Function GetAllUsersInGroup( groupname As String, Server As String, maxdepth As Integer ) As Variant
This function gets all the users in any group, including nested subgroups.
This is a RECURSIVE function, so be careful when modifying it.
MAXDEPTH is used to regulate how far down in group levels it can go.
If checking ACL groups, 6 is the limit, for mail groups its 20 -- but this can change with Domino versions in the future.
This sample code is distributed freely with only one obligation. You must distribute this code as a whole, including these comments, if you distribute it or re-use it at all.
For help, please contact
Northern Collaborative Technologies
' use static variables so that you can avoid repeatedly
' getting a handle to the same resources.
Static nab As notesdatabase
Static nabview As notesview
Static groupview As notesview
Static foundlist List As String
Static checkedgroups List As String
Static depth As Integer
' this is the list containing the results to return
Dim returnlist List As String
' just a stray string variable to be used
Dim tempstring As String
' set this to return the empty list, in case we have to exit due to error
getallusersingroup = returnlist
' since depth is a static variable, each recursive call to this
' function will increase its value. We can also decrease its
' value so we know when we're back to the initial call.
If depth => maxdepth Then Exit Function ' don’t look deeper then n nested groups
depth = depth + 1
' check to see if we haven't already connected to the nab & views
' if not, connect now.
If nab Is Nothing Then Set nab = New notesdatabase(server,"NAMES.NSF")
If nab Is Nothing Then Exit Function
If nabview Is Nothing Then Set nabview = nab.getview("($ServerAccess)")
If groupview Is Nothing Then Set groupview = nab.getview("($VIMGroups)")
If groupview Is Nothing Then Exit Function
If nabview Is Nothing Then Exit Function
Dim collection As notesdocumentcollection
Dim doc, checkdoc As notesdocument
Dim v As Variant
Dim count As Integer
Dim usercount As Integer
Dim user As notesname
' Now we get to the meat of the function
Set doc = groupview.getdocumentbykey(groupname, True) ' first, find the group
If doc Is Nothing Then Exit Function ' there is no group
Forall member In doc.members ' for each entry in the the group
tempstring = Ucase$(member)
' make sure we haven't already checked this entry
If Not Iselement(returnlist(tempstring)) Then
If Not Iselement(foundlist(tempstring)) Then
If Not Iselement(checkedgroups(tempstring)) Then
Set checkdoc = groupview.getdocumentbykey(tempstring, True)
If checkdoc Is Nothing Then
' treat as a user, add them to the return and found lists
foundlist(tempstring) = "1"
returnlist(tempstring) = "1"
' this is a new group to check
' so we recursively call this very function with the new groupname
checkedgroups(tempstring) = "1"
v = GetAllUsersInGroup( tempstring, server, maxdepth )
Forall newmember In v
' add the results from the recursive call to the return lists
returnlist(Listtag(newmember)) = "1"
foundlist(Listtag(newmember)) = "1"
' whew, now just return the list of all we found, plus all those found by
' any recursive calls we made, and the calls they made, and the calls they made, ...
getallusersingroup = returnlist
depth = depth -1
If depth = 0 Then
' this exit will be the last recursion, so delete the static list so we can run again if we need!
Open in new window
Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.
This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.