|
|
Count All Users Sample Code
Now Available 2.0!
Web Services Enabled |
Our newly released NCT Search 2.0 gives you the power to search across multiple Lotus Notes databases on the fly! Take control of your searches without the overhead of additional indexes. Search only the databases you want, when you want, and make the results display the way you want. NCT Search is your answer to multi-database searches.
Click here for informtion, Live Demo, and a free trial!
|
Technote submitted by Andrew Pollack
This code will count all the users in a group and any nested group. It does not include users who match the wildcard name (e.g. */org/domain). I plan to add that to this page but haven't had the time yet. The code is written so if you need it, let me know.
dim v as variant ' ends up being a list
dim counter as long
v = getallusersingroup(doc.groupname(0), groupdb.server)
counter = 0
Forall d In v
counter=counter + 1
End Forall
Function getallusersingroup(groupname As String, server As String) As Variant
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
Dim returnlist List As String
Dim tempstring As String
getallusersingroup = returnlist
If depth => 20 Then Exit Function ' don’t look deeper then 20 nested groups
depth = depth + 1
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
' first, find the group
Set doc = groupview.getdocumentbykey(groupname, True)
If doc Is Nothing Then Exit Function
Forall member In doc.members
tempstring = Ucase$(member)
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
foundlist(tempstring) = "1"
returnlist(tempstring) = "1"
Else
' this is a new group to check
checkedgroups(tempstring) = "1"
v = getallusersingroup(tempstring, server)
Forall newmember In v
returnlist(Listtag(newmember)) = "1"
foundlist(Listtag(newmember)) = "1"
End Forall
End If
End If
End If
End If
End Forall
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!
Erase foundlist
Erase checkedgroups
End If
End Function
|
|