You can retrieve a list of users in a group from the Domino directory based on a field value in an open document and present it in a message box to a user. Here's how:
- Create a new form.
- Create an editable dialog list field called "GroupNameTolookup."
- In Designer, enter the following formula on the second tab of the field properties. Also set the "Choices" to "Use formula for choices"
FullServerAdd:="SERVERNAME"; Filename:="names.nsf"; Server:=@Left(FullServerAdd;"/"); @DbColumn("":"NoCache";Server : Filename; "Groups";2) END OF FORMULA
- Create a button. Paste the following three sections of code behind the button. Note: This button is client LotusScript.
IN THE CLICK EVENT OF THE BUTTON PASTE THIS CODE: Dim ws As New notesuiworkspace Dim uidoc As notesuidocument Set uidoc=ws.currentdocument Dim fName As String fName= uidoc.FieldGetText ("GroupNameToLookup") Dim AllNames, tmpName As String Dim vGrpMembers As Variant vGrpMembers = GetGroupMembers(fName) For i = 0 To Ubound(vGrpMembers) tmpName = Strleft( vGrpMembers(i), "/") tmpName = Strright ( tmpName , "=" ) AllNames = allnames & i+1 & ") " & tmpName & Chr$(13) Next Messagebox "The member of the group " & fname & " are as follows:" & Chr$(13) & AllNames END OF CODE SECTION ONE CODE SECTION TWO IS A FUNCTION Function GetGroupMembers (strGrp As String) As Variant On Error Goto LocalErrHandler Dim Personview As NotesView Dim key As Variant Dim Persondoc As NotesDocument Dim Persondb As notesdatabase Set Persondb = getNames Set Personview = Persondb.GetView ( "Groups" ) key = strGrp Dim iValidDoc As Integer iValidDoc = 0 GetGroupMembers = True Set Persondoc = Personview. GetDocumentByKey(key) GetGroupMembers = Persondoc.Members Exit Function END OF CODE SECTION TWO CODE SECTION THREE IS ALSO A FUNCTION Function getNames As NotesDatabase Dim s As New NotesSession Dim db As NotesDatabase Set db = s.currentDatabase Set getNames=New NotesDatabase ("YOUR FULL SERVER NAME","names.nsf") End Function
Do not use the Groups view, prefer a hidden view such as $Groups (less risk when upgrading to a new version). Also, what about nested groups ?
This seems like a lot of code for something that should be very simple.
I like to create a hidden, multi-field Computed for Display field that uses the group selected in the first field. Then use whatever method required to display the names. (Modify the server as required.) Formula language is usually faster than LotusScript.
@IfError(@DbLookup("":"NoCache"; "": "names.nsf"; "($VIMGroups)"; GroupName; "Members"); @Return(""));
Where GroupName is the field name holding the group name.
Do you have comments on this tip? Let us know.
This tip was submitted to the SearchDomino.com tip exchange by member Gary Cronin. Please let others know how useful it is via the rating scale below. Do you have a useful Notes/Domino tip or code to share? Submit it to our monthly tip contest and you could win a prize and a spot in our Hall of Fame.