Tip

Add User To Group

' This sub adds a user to a group, but does it in a way
' that allows very large groups. Because Notes stores group members in
' text lists, and text lists can have only 15K bytes in them, simple groups
' are limited to around 1000 members. To have more members than that,
' the group must be broken into a number of other groups, which are
' then referenced as members of a master group.
'
' This sub handles all of that complexity. The group name passed in
' is the name of the master group, and this sub will handle the creation
' and populating of the sub-groups as needed. The sub-groups will
' be named by appending numbers to the master group name, and will
' have slightly more than 10K bytes of members in them.

Sub AddUserToGroup( Byval fullname As String, Byval group As String, nab As
NotesDatabase )

' Load up our static groups view

Dim groups As NotesView

Set groups = nab.GetView( "Groups" )

Dim groupMainDoc As NotesDocument
Set groupMainDoc = groups.GetDocumentByKey( group )
Dim saveGroupMainDoc As Integer
saveGroupMainDoc = False

If groupMainDoc Is Nothing Then
Set groupMainDoc = New NotesDocument( nab )
groupMainDoc.Form = "Group"
groupMainDoc.ListName = group
groupMainDoc.Members = group & " 1"
groupMainDoc.GroupType = "0"
Call groupMainDoc.ComputeWithForm( False, False )
saveGroupMainDoc = True
End If

Dim groupMainMembers As NotesItem
Set groupMainMembers = groupMainDoc.GetFirstItem( "Members" )

' Find last subgroup entry in the members list

Dim subGroup As String
subGroup = ""
Forall s In groupMainMembers.Values
If Left$( s, Len( group ) ) = group Then
subGroup = s
End If
End Forall

' Open the subgroup, and keep trying until we find one with room

Dim groupNum As Integer
groupNum = 0

' Which subgroup was the last one
If subGroup <> "" Then
groupNum = Val( Right( subGroup, Len( subGroup ) - Len( group ) - 1 )
)
Else
groupNum = 1
subGroup = group & " 1"
End If

Dim groupSubDoc As NotesDocument

Do
Set groupSubDoc = groups.GetDocumentByKey( subGroup )

If groupSubDoc Is Nothing Then
' Create a new subgroup document
Set groupSubDoc = New NotesDocument( nab )
groupSubDoc.Form = "Group"
groupSubDoc.ListName = subGroup
groupSubDoc.GroupType = "0"
Call groupSubDoc.ComputeWithForm( False, False )

' Add it to the main group if needed
If Not groupMainMembers.Contains( subGroup ) Then
Call groupMainMembers.AppendToTextList( subGroup )
saveGroupMainDoc = True
End If
End If

' See if the subgroup still has room, if so, we've found our subgroup

Dim groupSubMembers As NotesItem
Set groupSubMembers = groupSubDoc.GetFirstItem( "Members" )

If groupSubMembers.ValueLength < 10000 Then
Exit Do
End If

' If no room, try the next one

groupNum = groupNum + 1
subGroup = group & " " & groupNum
Loop

' Finally: add the user to the subgroup
Call groupSubMembers.AppendToTextList( fullname )
Call groupSubDoc.Save( False, True )

If saveGroupMainDoc Then
Call groupMainDoc.Save( False, True )
End If

End Sub

This was first published in November 2000

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.