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

    Server Performance

    Are your servers underperforming? Just buying new boxes isn't the answer. If you want to get better performance from your existing servers, Contact Me.
  • There are  - loading -  comments....

    re: Setting / Changing the UNID on documents - a fantastic hack for fixing problems or creating development copies of databasesBy Bob Balaban on 07/05/2008 at 13:31 EDT
    Comment Loading
    Another way to do this without codeBy Jamie Magee on 07/05/2008 at 17:57 EDT
    Comment Loading
    re: Setting / Changing the UNID on documents - a fantastic hack for fixing problems or creating development copies of databasesBy Kevin Pettitt on 07/05/2008 at 23:27 EDT
    Comment Loading
    re: Setting / Changing the UNID on documents - a fantastic hack for fixing problems or creating development copies of databasesBy Matt White on 07/06/2008 at 05:06 EDT
    Comment Loading
    Also used in the personal Calendar to "Import Holidays"By Kevin Pettitt on 07/06/2008 at 15:18 EDT
    Comment Loading
    re: Setting / Changing the UNID on documents - a fantastic hack for fixing problems or creating development copies of databasesBy John Marshall on 07/11/2008 at 08:54 EDT
    Comment Loading
    You are absolutely mistaken.By Andrew Pollack on 07/11/2008 at 09:42 EDT
    Comment Loading
    re: You are absolutely mistaken.By John Marshall on 07/11/2008 at 10:46 EDT
    Comment Loading
    re: You are absolutely mistaken.By John Marshall on 07/11/2008 at 10:48 EDT
    Comment Loading


    Other Recent Stories...

    1. 07/20/2010IBM has invented the time machine - and not in a good waySteve Mills is now in charge of both hardware and software. According to The New York Times.... The management changes, announced in an e-mail message to I.B.M. employees, were intended to improve the company’s products and services, Mr. Palmisano wrote. For example, computer hardware and software are for the first time being placed under the oversight of one executive......Increasingly, Mr. Palmisano wrote, computer systems must be “designed and brought to market as tightly integrated” packages of ...... 
    2. 07/18/2010A lot of work, but something I've always wanted to do -- Fixing up a car for one of my kidsOne of the things I've thought about for years and have always wanted to do, is to fix up a car for one of my kids. I'm not sure why, but its just something that I've thought about since they were really small. Of course, daydreams being what they are, the reality is never quite as grand in scale -- the 70's era muscle car turns out to be a 2002 Kia, and instead of an old pole barn to work in, the car is up on ramps in my driveway. Still, I'm really enjoying getting to do the work, being able to do the ...... 
    3. 07/13/2010Old Spice -- Their marketing team fully groks social media. You know the old spice guy (I'm on a boat)? I don't care for their products, but their ad people have gone social nuclear. Read this to see how they've totally "Got" social media promotion. ...... 
    4. 06/22/2010Product Review: Plantronics Savi Office wireless headset 
    5. 06/16/2010Ed Brill has a blog. Peter O'Kelly has blog... 
    6. 06/15/2010How about Traveler for Desktop? 
    7. 06/15/2010Why XPages is not LCD any more 
    8. 06/15/2010Fixing Domino Designer -  
    9. 06/14/2010Bandwagon: Why the decline in Notes seats, when the Domino server is still the best value on the marketplace? Here's why.... 
    10. 05/17/2010Unified Comunications Server? That ship sailed -- it's time to move on. 
    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.