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 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. 02/09/2014Changing what I do at the Fire DepartmentSo, here’s a bit of a change. A couple of weeks ago I let the chief know that it was time for me to step down as the Lieutenant of our Engine 1. Once a replacement is chosen, I’ll still be a firefighter but won’t be an officer any longer. There are a number of reasons for this, but the best explanation I can give is that it is time to let someone else grow into that role and make their own contribution, while at the same time I’ve got plenty of other things going on that keep me from putting as much time ...... 
    2. 02/07/2014Dammit. I think I broke facebook. ...... 
    3. 02/06/2014Sochi Olympics Pub Chat - Now OpenAs in years past, I've created a group Skype chat room for anyone who wants to use it while watching the Olympics. We've had fun with this in the past, as long as nobody takes it too seriously. Here's a link: skype:?chat&blob=1-XgYKMLG_kK5fqEsq4t4Jd4GLxHZxbMIqSYtCRXS9DiF5WNjBtuljOtcSDqaGdkOv5mX6paJQSuNuI ** Don't expect much traffic in there until Friday's opening event ** A few recommendations: 1. Definitely use the skype command '/alertsoff' so when you're not watching you won't get bugged by the rest of ...... 
    4. 02/05/2014Question for mobile app developers - what development platform do you recommend? 
    5. 02/03/2014Are you using a Surface Pro 2 or another Windows 8.1 Tablet? Want to use Traveler on the touch screen? It works! 
    6. 02/03/2014Some thoughts from IBM Connect 2014 
    7. 01/28/2014Understanding the decision behind Connections Mail 
    8. 01/19/2014Snap Review - Microsoft Surface Pro 2 - Tablet, Laptop Replacement, or Both 
    9. 10/31/2013You Need to Wish Gab Davis a Happy Birthday Today 
    10. 10/14/2013To connect or not to connect 
    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.