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.


  • text bubble icon

    Security Review

    How secure is your Domino environment? A security review doesn't have to be expensive to be helpful. If you're interested in finding out more, 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 01:31 PM EDT
    Comment Loading
    Another way to do this without codeBy Jamie Magee on 07/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 on 07/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 on 07/06/2008 at 05:06 AM EDT
    Comment Loading
    Also used in the personal Calendar to "Import Holidays"By Kevin Pettitt on 07/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 on 07/11/2008 at 08:54 AM EDT
    Comment Loading
    You are absolutely mistaken.By Andrew Pollack on 07/11/2008 at 09:42 AM EDT
    Comment Loading
    re: You are absolutely mistaken.By John Marshall on 07/11/2008 at 10:46 AM EDT
    Comment Loading
    re: You are absolutely mistaken.By John Marshall on 07/11/2008 at 10:48 AM EDT
    Comment Loading


    Other Recent Stories...

    1. 05/13/2013Successfully moved away from POSTINI to SPAMHERO - some thoughts...It's been almost a year since Google announced the changes in their "Postini" offering. I've been looking around, and finally chose to give [Spamhero] a try. As of today, I'm 100% switched over. Here's what I found, and a tip... Accuracy: I'm can definitely tell you is that Spamhero is accurate. I've had no false positives so far, and just a few spam messages that have gotten through. I had many more of both with Postini. For what spam does get through, you get a custom email address to forward the ...... 
    2. 03/22/2013BLUG A3 : Stuff Andrew Thinks You Should Know - The Presentation is now available for downloadThe BLUG conference was amazing. I had a great time, saw many people I really like, and watched a great deal of technical skill transfer take place as well as some wonderful peer to peer mentoring happening between some of the most experienced in our community and some of the newest members. Scott Souder gave a fantastic opening keynote talk that was fresh, frank, and encouraging. I love his energy and attitude, as well has his respect for the core products. Louis Richardson also did a great job. He makes ...... 
    3. 03/15/2013Looking at SAML and OAUTH in the Notes and Domino 9 Public BetaAm I reading this right? Seriously? Like many people, when I read that next release of the Domino Server and Client were going to support OAuth and SAML, I was pretty happy with that. I've been a bit late getting around to looking at the beta though -- after all, IBM has made it quite clear that my opinion isn't all that welcome any more -- and I'm just now reading the documentation on how IBM is going about this. I'll know more when I talk about this stuff next week at BLUG, by the way. First SAML. I know ...... 
    4. 02/11/2013Just made plane and hotel reservations for BNUG -- my first time at that event.  
    5. 02/03/2013Can Software be Too Social to Succeed? 
    6. 02/01/2013Thoughts about the Opening General Session at Connect 2013 -- Do you have any? 
    7. 01/27/2013Who is to blame for the failure of Domino as public web server? IBM (Lotus) Product Management 
    8. 01/21/2013Small progress taking the first real steps in moving Second Signal off IBM Domino 
    9. 01/08/2013Does the Executive Branch of the U.S. Government (the President) have the Constitutional Authority to _NOT_ spend money allocated by the Congress? 
    10. 12/29/2012Have made some progress in chosing a new platform. 
    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.