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....

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


    Other Recent Stories...

    1. 06/23/2009OpenNTF Licensing ChoiceOpenNTF should settle on the Apache Licensing. It allows IBM to consume OpenNTF released software for inclusion into the core product base -- which means really good stuff could get added in as default templates or parts of the mail file, etc. It also means developers can use Google code and other Apache Licensed software without worrying about being excluded from OpenNTF. As far as I'm concerned, if you don't agree, you're wrong -- and you should fork off (your own source tree) -- maybe call it ...... 
    2. 06/23/2009Web Developers and Artists -- What does a color really look like?The two images in the sample to the right - which LOOK like different colors, are not. they are the same web page and being displayed on the same computer with nearly the same settings. In both cases, the color is defined as "#15433D". [] The only difference, is that the one on top is shown in Firefox using the relatively little known feature introduced in version 3.x which uses the color profile configuration you have set up for your monitor when it renders images. These settings are ...... 
    3. 06/04/2009Product Review: Verizon's MiFiā„¢2200 Intelligent Mobile HotspotYou're not as connected as I am. If that's not true, you're a pretty unusually connected person. When I'm not in the office, I've used cellular tower based connections for several years. Originally it was just a cellular modem, then Verizon upgraded the network to "1xRTT" which gave speeds comparable to a dial-up line at home. EVDO came out and we boosted to the speed of a cheap DSL connection, and now with EVDO Rev A we can be connected almost anywhere with speeds nearly as good as any hotel or coffee ...... 
    4. 05/27/2009Second Signal - Starting to see the kind of growth I've been looking forward to 
    5. 05/26/2009Memorial Day 2009 - Slideshow of the parade, the marching band, the kids' bike parade, etc... 
    6. 05/21/2009Speaking at events that are not specific to our industry - Interesting Reaction 
    7. 05/19/2009Corporate Protectionism is as bad as the nationalistic kind 
    8. 05/17/2009Skippy, the Omega Dog! Freedom - thanks to the new "Dogwatch" fence 
    9. 05/17/2009This blog interrupted by the Lotus Design Partner Program 
    10. 04/24/2009Even more cool integration with the XLight FTP & SFTP Server to Domino - Upload/Download notificiations to the the Domino server 
    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.