Andrew Pollack's Blog

Technology, Family, Entertainment, Politics, and Random Noise

Setting / Changing the UNID on documents - a fantastic hack for fixing problems or creating development copies of databases

By Andrew Pollack on 07/05/2008 at 12:11 PM EDT

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.


  • car icon

    On Site Training

    We can bring the same kind of top quality training you get at conferences right to your offices. If your team needs training in a single topic, or you want to do a whole series on site, we can put a mini-conference together just for your team. For more information, Contact Me.
  • There are  - loading -  comments....



    Other Recent Stories...

    1. 09/04/2008If you could pick the topic you wanted from me at LS09, what would it be?Fall is here. Lotusphere 2009registration is open now, as is the call for abstracts. If you could pick my topic, what would you want me to cover? In the past, the Security Jumpstart I do with Gab has been very well attended with a repeat and both sessions really full, so we'll update that with all the new 8.5 stuff and submit that one for sure. Other than that, there's a ton of stuff I'm thinking about. Is there one you've seen me do that you think is worth repeating? Is there a new topic you think I ...... 
    2. 09/03/2008Trendspotting: What Google is really starting with ChromeAside from being a fairly cool -- if a bit undercooked -- new browser, Chome has another lesson for us. Google has very specifically NOT created an incremental bloatware version of existing code. They've built something new from nearly the ground up, embedding the proven technologies they needed -- javascript by V8, and rendering by Webkit. Only by starting from scratch were they able to get some of the size, memory management, and security enhancements that form the core of their promising new ...... 
    3. 09/03/2008Using the management of their campaigns to learn about the candidatesSome things about these two political campaigns have struck me recently as glimpses of what to expect from an administration led by either candidate. It isn't a perfect picture, but it is telling in a way. It also matches what I think about these two men so clearly my own viewpoint is mixed in richly in the interpretation. To be clear about that bias, I should state here that I am currently planning to vote for Obama, though will not vote an entirely Democratic party ticket. We have some very good ...... 
    4. 09/02/2008Chrome - Google's new Web Browser. Super tool, still needs a few things. 
    5. 08/30/2008Notes 8.5 Public Beta 2 - First impressions 
    6. 08/28/2008Have you used the Asus EEE PC? I've got a couple of unusual questions 
    7. 08/28/2008Blogging Respite - A long couple of weeks 
    8. 08/23/2008The disturbing case of the Fridge, and cabinets built by Dr. Seuess. * Updated with pictures 
    9. 08/17/2008From Caitlin: "Dad, are the Olympic medals solid gold?" The answer is interesting... 
    10. 08/12/2008The mis-use of Twitter as a chat room - and what to do about it 
    Click here for more articles.....


    pen icon Comment Entry
    Subject
    Your Name
    Homepage
    *Your Email
    * Your email address is required, but not displayed.
     
    Your thoughts....
     
    Remember Me  

    Please wait while your document is saved.