Manage Learn to apply best practices and optimize your operations.

Update ACL of selected databases

This code allows you to easily update the ACL (access control list) so that the administration server is changed from the old server to the new server in a migration.

We are in the process of moving a large number of databases from a single server to several servers. This code allows us to easily update the ACL (access control list) so that the administration server is changed from the old server to the new server. The old and new servers are selected from a dialog by the person making the changes. The new server is given all privileges and roles within the database. It also updates any agents scheduled to run on the old server so that they will run on the new server. The agent is set up to be called from a button on a view so that this code can be executed against all databases selected in the view. The "By Title" view in catalog.nsf is used to select the databases. One "Lookup Server" view has been added that is a simple view with one categorized column showing the fully qualified server names available.

Dim ws As New NotesUIWorkspace
 Dim s As New NotesSession
 Dim db As NotesDatabase
 Dim UpdateDb As NotesDatabase
 Dim doc As NotesDocument
 Dim InputDoc As NotesDocument
 Dim col As NotesDocumentCollection
 Dim v As NotesView
 Dim item As NotesItem
 Dim NewServer As Variant
 Dim OldServer As Variant
 Dim acl As NotesACL
 Dim entry As NotesACLEntry
 Dim summary As String
 Dim ModifyAgents As String
 Set ws = New NotesUIWorkspace
 Set s = New NotesSession
 Set db = s.CurrentDatabase
 Dim c0 As Single ' Docs Processed
 Dim c1 As Single ' Databases Updated
 Dim c2 As Single ' Errors Encountered
 Set col = db.UnprocessedDocuments
 If col.Count = 0 Then
  Msgbox "No documents are selected.  
Please select the document(s) you 
want to process and try again.", 64, "Error"
  Goto TheEnd
  Dim Answer As Integer
  Answer = Msgbox (col.Count & " 
document(s) have been selected." + 
Chr(13) +  Chr(13) + "Continue?", 4, "Warning!")
  If Answer = 7 Then
   Goto TheEnd
  End If 
 End If
 OldServer = ws.Pickliststrings(3, 0, 
Db.Server, Db.Filepath, "Lookup Server", 
"Server Picklist", "Select server to REMOVE.  
Use 'Cancel' to bypass removing any 
server from the ACL(s).", 1) 
 NewServer = ws.Pickliststrings(3, 0, 
Db.Server, Db.Filepath, "Lookup Server", 
"Server Picklist", "Select the server to ADD.  
Use 'Cancel' to bypass adding a server 
to the ACL(s).", 1) 
 Set doc = col.GetFirstDocument
 ModifyAgents = "Y"
 While Not (doc Is Nothing)
  c0 = c0 + 1
  Set UpdateDb = New NotesDatabase("","")
  Call UpdateDb.Open(doc.Server(0), 
  If UpdateDb.IsOpen Then
   c1 = c1 + 1
   If Isempty(OldServer) Then
    ModifyAgents = "N"
    Goto AddServerEntry
    If OldServer(0) = "" Then
     ModifyAgents = "N"
     Goto AddServerEntry
    End If
   End If
   Set acl = UpdateDb.ACL
'   Set entry = acl.GetFirstEntry
   Set entry = acl.GetEntry(OldServer(0))
   If Not (entry Is Nothing) Then
    Call entry.Remove
    Call acl.Save
    Goto AddServerEntry
   End If
   c2 = c2 + 1
   Summary = Summary + "Could not open " 
+ doc.Title(0) + ".  "
  End If
  If Isempty(NewServer) Then
   ModifyAgents = "N"
   Goto ProcessNextEntry
   If NewServer(0) = "" Then
    ModifyAgents = "N"
    Goto ProcessNextEntry
   End If
  End If
  Set acl = UpdateDb.ACL
  Set entry = acl.GetFirstEntry
  While Not entry Is Nothing
   If entry.Name = NewServer(0) Then
    Goto ProcessAgents
   End If
   Set entry = acl.GetNextEntry(entry)
  Set entry = acl.CreateACLEntry(NewServer(0), 6)
  entry.IsServer = True
  entry.IsAdminServer = True
  entry.IsAdminReaderAuthor = True
  Forall role In acl.Roles
   If role > "" Then
    Call entry.EnableRole(role) 
   End If
  End Forall
  Call acl.Save
  If ModifyAgents = "Y" Then
   Forall a In UpdateDb.Agents
    If a.ServerName = OldServer(0) Then
     a.ServerName = NewServer(0)
     Call a.Save
    End If
   End Forall
  End If
  Call s.UpdateProcessedDoc(doc)
  Set doc = col.GetNextDocument(doc)
 Msgbox Summary + "  Processed " + 
Cstr(c0) + " documents.  Updated " + 
Cstr(c1) + " databases.  " + Cstr(c2) + " 
errors encountered.", , "Processing 

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

Dig Deeper on LotusScript



  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/ community. These cheat ...

  • HTML cheat sheet

    This is a really cool cheat sheet if you're looking to learn more about HTML. You'll find just about everything you every wanted ...

  • Carol Woodbury: Security

    Carol Woodbury