Add/Remove groups and roles programmatically

The buttons below will add the groups from one field and assign each group the corresponding role from the role field. The index of each group and role must match for proper entry.
LotusScript

ADD GROUPS BUTTON

Sub Click(Source As Button)

Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As notesdatabase
Set db = session.currentdatabase
Dim uidoc As notesuidocument
Set uidoc =workspace.currentdocument
Dim doc As NotesDocument
Set doc = uidoc.document

Dim ACL As NotesACL
Set ACL = db.ACL
Dim ACLEntry As NotesACLEntry

For x = 0 To Ubound(doc.groupstoadd)
Set ACLEntry = ACL.CreateACLEntry ( doc.groupstoadd(x), ACLLEVEL_EDITOR )
ACLEntry.CanDeleteDocuments = True
ACLEntry.IsGroup = True
ACLEntry.UserType = 4

Call ACLEntry.EnableRole( doc.Roles(x) )
Call ACL.Save
Next

Print x & " group created"

End Sub

REMOVE GROUPS BUTTON

Sub Click(Source As Button)
	
	Dim workspace As New NotesUIWorkspace
	Dim session As New NotesSession
	Dim db As notesdatabase
	Set db = session.currentdatabase
	Dim uidoc As notesuidocument   
	Set uidoc =workspace.currentdocument
	Dim doc As NotesDocument
	Set doc = uidoc.document	
		
	Dim ACL As NotesACL
	Set ACL = db.ACL
	Dim ACLEntry As NotesACLEntry
	
	For x = 0 To Ubound(doc.groupstoadd)
		Set ACLEntry = ACL.getEntry ( doc.groupstoadd(x) )
		Call aclentry.remove
		Call ACL.Save
	Next
	
	Print x & " group deleted"
	
End Sub

Images/Screenshots:






Posted by fbrefere001 on Monday March 3, 2003