Manage Learn to apply best practices and optimize your operations.

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 )
groupNum = 1
subGroup = group & " 1"
End If

Dim groupSubDoc As NotesDocument

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

' 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 last published in November 2000

Dig Deeper on Domino Resources - Part 2

Start the conversation

Send me notifications when other members comment.

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

Please create a username to comment.




  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...