Manage Learn to apply best practices and optimize your operations.

Remove User IDs from Domino Directory

Have you ever had the tedious task of removing all of the user IDs from the Domino Directory. I refused to go through the edit, detach, remove attachment, save cycle. Below is an agent that will detach all of the user IDs to a specified directory.

The ID files are based on the person document's short name or the server documents full name. The agent will check for possible duplicates and make a tie breaker.

The code is written for easy modification to traverse different views.

Code: Sub Initialize
  On Error Goto err_Detach
  Const DetachDir$ = "C:DPottsNotesIDs"  ' Note there is no "/" on the end
  Const GetFileNamesMacro$ = "@AttachmentNames" 'Declare a Notes macro
  
  Dim session As New NotesSession
  Dim view As NotesView
  Dim db As NotesDatabase
  Dim doc As NotesDocument
  Dim tDetachName As String  
  Dim There As String
  Dim aViews(1)
  Dim I As Integer
  Dim iPos As Integer  
  Dim nDup As Integer
  Dim fileInDocCount As Integer
  
  'Check if the DetachDir exists (if on network & permission problem, error code will catch it)
  There$ = Dir$(DetachDir$, 16)
  
  If There$ = "" Then
    Messagebox "The directory " + DetachDir$ + " does not exist. "  _ 
    +  "  Detach process terminated!", 16, "Invalid Directory"
    Exit Sub
  End If
  aViews(0) = "People"
  aViews(1) = "Servers"
  
  Set db = session.CurrentDatabase
  
  For i = 0 To 1
    Set view = db.GetView(aViews(i))
    Set doc = view.GetFirstDocument
    
    While Not (doc Is Nothing)
      
      Select Case doc.Form(0) ' Using arrays and case statement for easy modification of code
      Case "Person":
        tDetachName$ = doc.shortname(0)
      Case "Server":
        tDetachName$ = doc.ServerName(0)    
        
        ' Now de-canonicalize the name. If flat certifiers are used, no change will be made to the server name
        iPos% = Instr(1, tDetachName$,  "=") ' Look for the "CN=". Usually found at 3rd position or cononical server name
        
        If iPos% > 1 Then
          tDetachName$ = Mid$(tDetachName$, iPos + 1)
        End If
        
        iPos% = Instr(1, tDetachName$, "/") ' Looking for the OU and ORG, etc  info
        
        If iPos% > 1 Then
          tDetachName$ = Left$(tDetachName$, iPos - 1)
        End If
      End Select
      
      iPos = Len(tDetachName$) ' Get the length of the string for use later
      
      tDetachName$ = tDetachName$ + ".ID"
      
      ' See if the file is already there
      There$ = Dir$(DetachDir$ + "" + tDetachName$)
      
      nDup% = 0
      
      While There$ <> ""
        nDup = nDup + 1
        tDetachName$ = Mid$(tDetachName$, 1, iPos) _
        + Trim(Str(nDup)) + ".ID"
        
        There$ = Dir$(DetachDir$ + "" + tDetachName$)        
      Wend
      
      Print "Detaching " + tDetachName$ + " to " + DetachDir$ + "....."
%REM
===========================
= Now detach the attachments   =
===========================
%END REM
      If doc.HasEmbedded Then    
        attachNames = Evaluate(getFileNamesMacro$, doc) 'Get the name(s) of the files attached in the current document               
        fileInDocCount% = 0 'Set the document file counter to 0 for each document
        
                    ' Detach the attachments
        Forall Attachment In attachNames 'Process all the files within the current document
          On Error Goto NextObject
          Set object = doc.GetAttachment(attachNames(fileInDocCount%)) 'Must associate the file name with a Notes object to use the ExtractFile method below
          If Not (object Is Nothing) Then
            If object.Type = EMBED_ATTACHMENT Then
              
                        ' See if the file is already there
              There$ = Dir$(DetachDir$ + "" + tDetachName$)
              
              nDup% = 0
              
              While There$ <> "" ' I am assuming that a reasonable tie breaker will be found. Otherwise, nDup increment to a high #
                nDup = nDup + 1
                tDetachName$ = Mid$(tDetachName$, 1, iPos) _
                + Trim(Str(nDup)) + ".ID"
                
                There$ = Dir$(DetachDir$ + "" + tDetachName$)        
              Wend
              
              Call object.ExtractFile(DetachDir$ + "" + tDetachName$) 'Extract the file to the selected directory 
              Call object.Remove
            End If  'object.Type = EMBED_ATTACHMENT
          End If 'Not (object Is Nothing) 
          
          On Error Goto err_Detach        
          fileInDocCount% = fileInDocCount% + 1 'Increment the count for the number of files within the current document 
NextObject:        
        End Forall  'Attachments
      End If 'doc.HasEmbedded
      
      Call doc.Save(True, False) 'Save the document
      Set doc = view.GetNextDocument(doc) ' Get next document in the view
      
    Wend ' Not (doc Is Nothing)
  Next ' Next i - Get the next view name in the aViews array
  
  Print "All attachments have been removed."
  Exit Sub
  
err_Detach:  
  Messagebox "Error " + Str(Err) + " - " + Error$ + " occurred at line " _
  + Str(Erl()) + " while detaching " + tDetachFile$ + " to " + DetachDir$, 64, "Detach Error"
  Exit Sub
End Sub

Dig Deeper on Lotus Domino Directory

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

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 ...

SearchDataCenter

SearchContentManagement

Close