SPOC Utility Agents

Copy companies:

Sub Initialize
   Dim s As New NotesSession
   Dim dbTarget As NotesDatabase
   Dim dbSource As NotesDatabase
   Dim docSource As NotesDocument
   Dim docTarget As NotesDocument
   Dim viewSource As NotesView
   Dim viewTarget As NotesView
   Dim copy_count As Integer

   Set dbSource = s.CurrentDatabase
   Set dbTarget = s.GetDatabase("server", "spoc.nsf")
   Set viewTarget = dbTarget.GetView("lookupMainFirmById")
   Set viewSource = dbSource.GetView("lookupMainFirmById")
   viewTarget.AutoUpdate = False
   viewSource.AutoUpdate = False

   Set docSource = viewSource.GetFirstDocument
   While Not (docSource Is Nothing)
      Set docTarget = viewTarget.GetDocumentByKey(docSource.ID(0), True)
      If docTarget Is Nothing Then
         copy_count = copy_count + 1
         Call docSource.CopyToDatabase(dbTarget)
      End If

      Set docSource = viewSource.GetNextDocument(docSource)
   Wend

   Msgbox "Copy count=" & copy_count
End Sub

Copy contacts:

Sub Initialize
   Dim s As New NotesSession
   Dim dbTarget As NotesDatabase
   Dim dbSource As NotesDatabase
   Dim docSource As NotesDocument
   Dim docTarget As NotesDocument
   Dim viewSource As NotesView
   Dim viewTarget As NotesView
   Dim copy_count As Integer

   Set dbSource = s.CurrentDatabase
   Set dbTarget = s.GetDatabase("server", "spoc.nsf")
   Set viewTarget = dbTarget.GetView("lookupContactsByUnique")
   Set viewSource = dbSource.GetView("lookupContactsByUnique")
   viewTarget.AutoUpdate = False
   viewSource.AutoUpdate = False

   Set docSource = viewSource.GetFirstDocument
   While Not (docSource Is Nothing)
      Set docTarget = viewTarget.GetDocumentByKey(docSource.ContactUnique(0), True)
      If docTarget Is Nothing Then
         copy_count = copy_count + 1
         Call docSource.CopyToDatabase(dbTarget)
      End If

      Set docSource = viewSource.GetNextDocument(docSource)
   Wend

   Msgbox "Copy count=" & copy_count
End Sub

Copy e-mails:

Sub Initialize
   Dim s As New NotesSession
   Dim dbTarget As NotesDatabase
   Dim dbSource As NotesDatabase
   Dim docSource As NotesDocument
   Dim docTarget As NotesDocument
   Dim viewSource As NotesView
   Dim viewTarget As NotesView
   Dim copy_count As Integer
   Dim docEmailSource As NotesDocument
   Dim docEmailTarget As NotesDocument
   Dim dc As NotesDocumentCollection

   Set dbSource = s.CurrentDatabase
   Set dbTarget = s.GetDatabase("server", "spoc.nsf")
   Set viewTarget = dbTarget.GetView("lookupContactsByUnique")
   Set viewSource = dbSource.GetView("lookupContactsByUnique")
   viewTarget.AutoUpdate = False
   viewSource.AutoUpdate = False

   Set docSource = viewSource.GetFirstDocument
   While Not (docSource Is Nothing)
      'find contact in target spoc
      Set docTarget = viewTarget.GetDocumentByKey(docSource.ContactUnique(0), True)

      'get responses
      Set dc = docSource.Responses
      Set docEmailSource = dc.GetFirstDocument
      While Not (docEmailSource Is Nothing)
         'copy
         Set docEmailTarget = docEmailSource.CopyToDatabase(dbTarget)
         Call docEmailTarget.Save(True, False)

         'make response
         Call docEmailTarget.MakeResponse(docTarget)

         'increment count
         copy_count = copy_count + 1

         'get next
         Set docEmailSource = dc.GetNextDocument(docEmailSource)
      Wend

      'get next
      Set docSource = viewSource.GetNextDocument(docSource)
   Wend

   Msgbox "Copy count=" & copy_count
End Sub