Subject: Want to retain unid when copying docs to new database - LOTUSCRIPT INCLUDED
Create an agent with the code below in the source database and run it from the Actions menu. It will ask for the destination.
I’ve successfully used this a number of times to combine two NABs where one of the domains has a Blackberry server - which references Person docs via UNID.
Hope it helps,
Simon
=================
(Declarations)
Dim errorlist() As String
===========================================
Initialize
Sub Initialize
On Error Goto ErrorHandler
Dim s As New NotesSession
Dim ws As New NotesUIWorkspace
Dim thisdb As NotesDatabase
Dim targetdb As notesdatabase
Dim doc As NotesDocument
Dim coll As notesdocumentcollection
Dim thisagent As NotesAgent
targetdbname = ws.Prompt(13,"Choose database","Choose target database")
Set targetdb = s.GetDatabase(targetdbname(0),targetdbname(1),False)
Set thisdb = s.CurrentDatabase
Set coll = thisdb.UnprocessedDocuments
Set doc = coll.GetFirstDocument
Redim Preserve errorlist(0)
Do While Not doc Is Nothing
Call copydocument(targetdb, doc, False)
Set doc = coll.GetNextDocument(doc)
Loop
Dim memo As New NotesDocument(thisdb)
memo.body = errorlist
Call memo.Send(False, s.UserName)
Exit Sub
ErrorHandler:
Print "Error: " & Err & " - " & Error$
Exit Sub
End Sub
===========================================
CopyDocument (subroutine)
Function CopyDocument ( db As NotesDatabase, sdoc As NotesDocument, RemoveDoc As Integer ) As Integer
'*** Christoph Berger / Switzerland ***
'*** This function copies a document from the source DB to the destination DB. ***
'*** The UNID remains the same, therefor, the script checks if another document with ***
'*** the same UNID exists and either removes the existing document or it doesn’t copy the document. ***
'*** db represents the destination database, sdoc = Source, ndoc = New Document, ***
'*** RemoveDoc = If the existing doc can be removed ***
Dim ndoc As NotesDocument
Dim strID As String
'*** init ***
CopyDocument = False
strID = sdoc.UniversalID
'*** Check if a document with the same UNID exists and remove it if necessary / possible ***
On Error Resume Next
Set ndoc = db.GetDocumentByUNID( strID )
If ( Not ( ndoc Is Nothing ) ) Then
errorlist(Ubound(errorlist)) = "UNID already exists " & strID & " " & sdoc.fullname(0) & Chr(10) & Chr(13)
Redim Preserve errorlist(Ubound(errorlist) +1)
Exit Function
End If
'If ( Not ( ndoc Is Nothing ) ) And ( Not RemoveDoc )Then Exit Function
'If Not ( ndoc Is Nothing ) Then Call ndoc.Remove ( True )
'On Error Goto 0
'*** Create the doc, copy everything and set the UNID ***
Set ndoc = db.CreateDocument
Call sdoc.CopyAllItems( ndoc, True )
ndoc.UniversalID = strID
'*** Save the new doc ***
Call ndoc.Save ( True, True )
CopyDocument = True
End Function