Retrieve the number of people in a group

This code will help you retrieve the number of people in a group. It will even work if a group is nested within multiple groups.


Dim count As Integer
Dim persons List As String
Dim groups List
Dim tg As Integer
Dim xy As Integer

Sub Initialize
'The advantate of this code is that 
we can process any nested groups 
without any size limitaions.
 Dim session As New notessession 
 Dim ws As New notesuiworkspace
 Dim uidoc As NotesUIDocument
 Dim db As notesdatabase
 Dim namesdb As notesdatabase
 Dim groupdoc As notesdocument
 Dim groupview As notesview
 Dim insidegroupdoc 
As notesdocument
 Dim insidegroups As notesview
 Dim doc As notesdocument
 Dim curview As notesview
 Dim newlist List
 Set db=session.CurrentDatabase
 Set namesdb=session.GetDatabase
 Set groupview=
 Set insidegroups=
 Set curview=db.getview("second")
 Set uidoc=ws.CurrentDocument
 Set doc=curview.getfirstdocument 
'you can set your own doc here.  
This the 
backend document for the currently
 opened uidoc.  You can find other 
alternatives to run this agent.
 groupName$ =uidoc.FieldGetText("names")  
' Here we are entering the group or 
person names.
 Dim ritem As Variant
 Set ritem = doc.GetFirstItem( "all" ) 
' Here we are going to store the group 
extracted people's name
 'Call uidoc.FieldSetText("saveoptions","1")
 Call uidoc.FieldSetText("Total","")
 ' Here we will list the total participant 
 Call uidoc.FieldSetText("all","")
 ' making the field null to print a new 
 Call uidoc.Save
 Call uidoc.reload
 Call uidoc.save 
 Forall entry In doc.names
  gtype=group(entry)   'Checking 
whether the entry is a group or People.
  If gtype="Group"  Then
   Call addtolist(entry) ' If entry is a
 person, then adding to a list called 
  End If
 End Forall 
'now we have got two lists one is 
person and another one is group 
'This loop will returns you a list 
in the people's view. and remove the each 
group entry after processing. 
 Do Until xy = tg
  Erase groups(xy)
 If ( ritem.Type <> RICHTEXT ) Then
  Exit Sub
 End If
'Iam adding the list to another array, 
because iam not getting the list with 
unique values.  You can try some 
other code if you can retruns the list as 
 Dim nar() As String
 Forall nvals In Persons
  Redim Preserve nar(newcount)
 End Forall
'Then make the array as unique 
'Now print the values one by 
one in an array.   See if you 
want to process the 
contents of this rtfield.
'  Use the item.values and 
split the values using newline.  
So you will get an 
 Forall fins In finarray
  If fins <> "" Then
   Call ritem.Appendtext(fins)
   Call ritem.addnewline(1)
  End If
 End Forall   
'This code will close the doc 
without saving and re-open it. 
 Call doc.ReplaceItemValue
 Call doc.save(True,True)
 Call uidoc.close
 Call ws.EditDocument(False,doc)  
'You can use the notesname 
class to format the contents 
and use the evaluate 
to sort the contents.  
The code you can get it from my 
'Other agent in the 
same db. 
End Sub

Function group(entry As Variant) 
As String
'Getting first 3 characters will give 
u an idea whether it is a group or 
person.  In our case every user 
will have a heirarhical name.  In your case 
you can use ur own code to get this info. 
 If Left(entry,3)="CN=" Then
 End If
End Function

Function addtolist(entry As Variant)
 If Isarray(entry) Then 
' In some rare cases by mistake 
or so we have two 
entries in a document.  So run
 this check before proceed.
  Forall ad In entry
  End Forall
 End If 
End Function

Function groupget(gview As 
notesview,entry As Variant) As String
'here first we are getting group name.  
Then get the group document and get 
the members for the group.  
Then add the person entries to Person array.
'Rest group entries will add to group list. 
 Set groupdoc=
 If Not groupdoc Is Nothing Then 
  Forall ent In allentries
   'Set pdoc=
   If Left(ent,3)="CN=" Then 
   End If     
  End Forall
 End If
End Function

Do you have comments on this tip? Let us know.

This tip was submitted to the SearchDomino.com tip exchange by member Prasad KL. 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.

This was first published in November 2004

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.