Want to retain unid when copying docs to new database

I have an existing database A and a new version of that database B. The new version will accumulate documents for a while, and documents in both A and B have response docs and views that utilize the UNID. I will eventually have to move the docs in B to A.

Only one form (“project”) serves as the parent. All other forms are responses to the parent. I need some advice on retaining the UNID. I have read a few solutions and thought of my own, but would the following work? I’m open to ideas.

Step 1. Before copying from B, duplicate the UNID in another field: UnidCopy.

Step 2. Then after copying all the docs from B to A, run an agent that calls sets the UniversalID on the project documents to the value of UnidCopy making sure to peform this only for docs that have a legitimate non-empty string in UnidCopy. (Don’t do anything with responses because $REF will not have changed.)

Subject: Would it be easier to use replication settings?

I am not sure what your criteria is for copying. But it may be easier to setup some replication settings to replicate the docs to dbB, not replicate deletions, then delete them from dbA.

Just a thought.

Subject: They’re not replicas

Unfortunately, they’re not replicas. They reside on the same sever. In an ideal world, I would have replicas with a different design for A (for stability) and B (for the new instance). But they’re both going to be on the same server, and I can’t just put the design of B (the new design) on A right now. Eventually I will replace A’s design, and then the docs in B must be copied to A, and B will go away. But the docs created in B while it was living will have to retain their UNID (or have it reset to the original value after the copy) so that response docs know to whom they belong.

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

Subject: Thanks for the code

I appreciate this very much. I see that I can set my collection to whatever I want. This will work for me.

Thanks you Simon, Christoph Berger (wherever you are, for writing part of that code), and to the others who responded.

Subject: Want to retain unid when copying docs to new database

We do virtually the samething for an archive DB when the users need to restore things.

My question for you, is when things are on Server B, will anyone be adding response documents to existing doucments? (As you don’t seem to plan to change $ref).

Also what about when things are on Server B, don’t you want $ref to point to the original documents incase someone wants to look at the parent? For this reason we did the samething with $ref - set it to origRef and recalculated $ref to point to the new UNID of the parent.

Subject: RE: Want to retain unid when copying docs to new database

Copies A and B will live on their own for a while. Then the design of A will be upgraded and all docs in B will be transfer to A to join their relatives, and B will go away.

Since $Ref won’t be altered by the copy, I thought I’d just gather the projects (parent) docs that were created in B and reset their Unids after they are copied to A. Then all the responses should find their parents again. It looks like you do the opposite - get the new ID of the parent and propogate it out to $Ref on the children.