Credit where it's due, Nathan brought this one to my attention. He's using the technique for something else he'll be blogging about later with a great deal of excitement. When he told me what he was doing, I wasn't as interested in how he was using it as he was (have to keep that part a secret) but I was pretty interested in the little hack he's taking advantage of.
You can set the Universal ID on a Notes Document. I wasn't aware of this, but in lotusscript, NotesDocument.UniversalID is not a read-only property. You can set it. You need to be extremely careful with this, as you can really screw things up. That said, there are a few good uses. Here are two of mine:
1. Have you ever had to re-create a document that was deleted but due to the replica ID being different it messed up your response hierarchy or lookups, or whatever? Just set the UniversalID to the one the old document had (you can get it from the $REF field on a child document, for example) and your child documents or lookups, or web url's all work.
2. For making a non-replica copy of a database to do design work on, create the copy of the database with "Design Only". Once done, create a quick agent to copy all the documents from the original to the new copy, re-assigning their Universal ID in the process. This gives you a very nice non-replica to work with.
Here's a script I used:
Dim session As New notessession
Dim thisdb As notesdatabase, otherdb As NotesDatabase
Set thisdb= session.CurrentDatabase
Set otherdb = New notesdatabase(thisdb.Server,"otherdb.nsf")
Dim col As notesdocumentcollection
Dim newdoc As notesdocument, olddoc As notesdocument
Set col = otherdb.AllDocuments
If Not col.count = 0 Then Set olddoc = col.GetFirstDocument
While Not olddoc Is Nothing
If olddoc.IsValid Then
Set newdoc =New notesdocument(thisdb)
newdoc.UniversalID = olddoc.UniversalID
Call olddoc.CopyAllItems(newdoc)
Call newdoc.Save(False, False, False)
End If
Set olddoc=col.getnextdocument(olddoc)
Wend
Some things to note about using this technique:
First: If you take an existing document, change its UNID and save it, you're creating a new copy of the document. The old one is still there. You'll have to delete the duplicate. For a workaround to this, create a new document that hasn't been saved yet, copy the unid from the original onto the new document, then use originalDoc.copyAllItems(newdoc) and finally save the new doc. This will prevent duplication.
Second: If you try to re-use the same UNID that exists already, you'll get an error on the save. Two docs in the same database can't have the same UNID and you'll get an error.
Third: If you use this technique and make two docs with the same UNID in different replica copies of the database, you'll get replication conflicts when they meet.
There are other concerns, but you'll have to bug Nathan to post his blog entry about what he's doing since I'd be giving things away if I went down that road.
Comment Entry |
Please wait while your document is saved.
done this in C before, don't really know how easy/impossible it might be in LS