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 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. 02/06/2010When does an application stop belonging to its owner?When an application becomes truly successful and people start relying on it for things they consider important, is there a point at which the application starts to belong to the owners? Facebook's latest change brings the topic to mind, but it can happen to you with internal applications as well. There comes a time when users begin to have a personal stake in the design of a good application. Facebook makes a great example for when your users really own your application. Its user base is both extremely ...... 
    2. 01/29/2010Lotusphere 2010 - Session Survey ResultsSession results are always a bit strange to go through. I want to share what they looked like for me this year. Nearly all the comments were outstanding - but there's always one that really leaves me scratching my head. Like most speakers who take that part of their work seriously, I try to look at every survey, and pay extra attention to ones with written comments to see if there are things I can do better for next time. You have to grow a bit of a thick skin sometimes because there are always some ...... 
    3. 01/27/2010Is UPS just plain broken? * Updated* Updated January 27th -- Notes at the end of the original story. UPS is usually pretty reliable. My experience, however, has been that if the smallest thing goes wrong the whole process grinds to an inexplicable halt. Let me show you an example. On the 20th (a Wednesday) Lenovo shipped three packages to me. Two of them came from China. The first made the trip in the expected (and paid for) two days. The second seems to have spent days sitting in Shanghai and has so far chained itself to the wall in ...... 
    4. 01/25/2010My presentations posted here from Lotusphere 2010 
    5. 01/24/2010Me - in bobblehead form 
    6. 01/23/2010Announcing the C.U.L.T. Shirt 2010 Winner 
    7. 01/19/2010Great round table with Kristen Lauria about the Lotus Knows campaign 
    8. 01/19/2010The Review: Lotusphere 2010 – Opening General Session 
    9. 01/10/2010The LiveScribe Pen - Reviewed  
    10. 12/11/2009Comparing the iTouch/iPhone with the Blackberry Storm from a Notes Mail user & Geek perspective 
    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.