NotesGroupManager?

I’ve been trying to dissect this one but need a little guidance…

I am building a custom search form that will search a particular email archive for users and/or groups.

I can get all the groups a user is a member of. What I’d like to do is create a listing of what groups this list of groups is a part of.

So if ‘Jack’ is a member of ‘East Coast Sales’ and ‘Company Softball Team’ I’d like to effieciently figure out where these groups are nested. I don’t need the people at this point, just the names.

Am I making this more complicated that it needs to be?

Subject: NotesGroupManager ?

You might want to take a peek at this developerWorks article on working with groups in LS:

Subject: RE: NotesGroupManager ?

Thanks for your response. I’ve been trying to use that one but am having a tough time accessing the’m_subgroups’ list. I’m trying to use this through a button…

Maybe you can tell me where I’m going wrong?

Sub Click(Source As Button)

Dim s As New notessession	

Dim gman As New NotesGroupManager(True)

gman.LoadPublicAddressBooks

Dim group As NotesGroup

Dim db As notesdatabase

Dim workspace As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim doc As NotesDocument

’ Dim subgroups As Variant

Dim recipients As Variant

Dim strSubName As String



Set db=s.CurrentDatabase

Set uidoc = workspace.CurrentDocument

Set doc=uidoc.Document



recipients = doc.GetItemValue( "GroupName" ) 

Forall listings In recipients		

	Set group = gman.GetGroup(listings)

	If group Is Nothing Then

		Print "group not found"

		

	Else 

'???

	End If

End Forall

Many thanks

Subject: RE: NotesGroupManager ?

What is the problem? Are you getting an error? You don’t have any error-trapping defined; I would certainly recommend using it.

Sub Click(Source as Button)

On error goto errhand

'all your other code

errhand:

msgbox "Error at line " & erl & ": " & error

exit sub

End Sub

Subject: RE: NotesGroupManager ?

I’m not able to get a handle on the subgroups information once I get the group.

Subject: RE: NotesGroupManager ?

Set group = gman.GetGroup(listings)If group Is Nothing Then

Print “group not found”

Else

Forall sg in group.Subgroups

Print sg.Name

End forall

End If

Subject: RE: NotesGroupManager ?

Thanks for your quick response – I really appreciate the help!

I’m getting a ‘Type Mismatch’ error on

Print sg.Name

Subject: RE: NotesGroupManager ?

make that sg.Name(0)

Subject: RE: NotesGroupManager ?

still ‘type mismatch’

???

Subject: RE: NotesGroupManager ?

I’ve not spent a whole lot of time with these classes; it looks like Subgroups is a LS list.

Try:

Forall sg in group.Subgroups

Print ListTag(sg)

End forall

Subject: RE: NotesGroupManager ?

You are my hero! I GREATLY appreciate the timee you (& everyone) have spent with me on this.

I don’t know what it was but I just couldn’t wrap my head around this one.

Thanks again!

FYI - Code that works:

Sub Click(Source As Button)

Dim s As New notessession	

Dim gman As New NotesGroupManager(True)

gman.LoadPublicAddressBooks

Dim group As NotesGroup

Dim db As notesdatabase

Dim workspace As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim doc As NotesDocument

Dim recipients As Variant

Dim strSubName As String



Set db=s.CurrentDatabase

Set uidoc = workspace.CurrentDocument

Set doc=uidoc.Document



recipients = doc.GetItemValue( "GroupName" ) 

Forall listings In recipients	

	

	Set group = gman.GetGroup(listings)

	If group Is Nothing Then

		Print "group not found"

		

	Else

		Forall sg In group.Subgroups

			Print Listtag(sg)

		End Forall 

		

	End If 

	

End Forall

End Sub

Subject: RE: NotesGroupManager ?

well not exactly what I needed afterall (but thank you for getting that to work)

Here’s the scenario: I have a user or a group that is a subgroup of ABC which is a Subgroup of DEF which is a subgroup of GHI. So instead of finding the other subgroups of ABC i’d like to return DEF and GHI.

So in the end I’d like to return “Joe Smith is a member of ABC which is a member of DEF which is a member of GHI” (and if necessary the DEF is a member og LMNO and XYZ, etcetera, etcetera, etcetera.)

Subject: RE: NotesGroupManager ?

The NotesGroupManager doesn’t expose any methods for determining which groups – out of all of them – a particular person or group is a member of. However, you could write yourself a little subroutine.

Question is, what form should the output take? You expressed it as a string, but the hierarchy of group inclusion can get sort of complex, making this difficult to read. Ron is a member of Zam, which is a member of Grod and Pinkie, which is a member of Treacle, which is a member of Scoop and Fantod, Hoops, which is a member of Spaghetti, and Umbrella.

It might be better to shoot for a graphical or list-indented display of the results, e.g.:

Ron

  • Zam

    • Grod
    • Pinkie
      • Treacle
        • Scoop
        • Fantod
  • Hoops

    • Spaghetti
  • Umbrella

You could create such output using a recursive routine that scans the list of groups at each level looking for a particular name. Depending how many of these things you want to do in a single execution, though, it might be more efficient to create a reverse lookup list in memory, indexed by person/group name, that lists the groups of which that person or group is a member.

Here’s how you might do the former version – you can try it out in the group manager sample database with the name James Hook/BadGuys/Neverland:

Option Public
Option Declare
Use “GroupManager”

Const NEWLINE = {
}
Sub Initialize
Dim session As New NotesSession
Dim dbCurrent As NotesDatabase
Dim gman As New NotesGroupManager(False)
Dim group As NotesGroup

Set dbCurrent = session.CurrentDatabase
Call gman.LoadAddressBook(dbCurrent)
Call gman.LoadAllGroups
Dim cache As Variant
cache = gman.CachedGroups ' more efficient to request this only once.

Dim strInput As String, strResult As String
strInput = Inputbox("What name do you want to look up?")
If strInput <> "" Then
	strResult = GroupHierarchyOf(cache, strInput)
	Msgbox strResult, 0, "Your answer"
End If

End Sub

Function GroupHierarchyOf(cache As Variant, strWho As String) As String
GroupHierarchyOf = strWho
Forall grp In cache
If grp.IsMember(strWho) Then
GroupHierarchyOf = GroupHierarchyOf & NEWLINE _
& Indent(GroupHierarchyOf(cache, grp.Name))
End If
End Forall
End Function

Function Indent(strIn) As String
Indent = " - " & Replace(strIn, NEWLINE, NEWLINE & " - ")
End Function

Note that this doesn’t find wildcards or variants, e.g. groups that contain James Hook as a common name, or */Neverland. You would have to do that yourself and merge the results.

Subject: RE: NotesGroupManager ?

you are my hero… Thanks so much for your help! I always get so much out of your posts and articles.

I’d actually like to do 2 things – one is to display to the hierarchy for the user (thank you) and the other is populate a field with these values.

I am creating a search function for a few users that will allow them to ftsearch our monthly mail archive dbs and copy these docs to another db for further review.

I’d like to dynamically create the strings as well as save the searches. I’m only searching all of the various the ‘to’ and from ‘fields’… now if I can just get around the 5000 doc ftsearch limitation… I imagine that I will search for one term at a time and delete any duplicates later to avoid this issue.

(I will post my final code for the slim chance it will help someone else)

thx again!