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

Dig deeper on Domino Resources - Part 2

0 comments

Oldest 

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:

-ADS BY GOOGLE

SearchWinIT

Search400

  • iSeries tutorials

    Search400.com'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 ...

SearchEnterpriseLinux

SearchVirtualDataCentre.co.UK

Close