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)

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.

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
You can also change the UNID of a document to modify the creation date. I've
done this in C before, don't really know how easy/impossible it might be in LS
Another way to do this without codeBy Jamie Magee on 07/05/2008 at 05:57 PM EDT
NoteMan Toolbar ( lets you ad hoc change the UNID of any
doc in two clicks (but not yet in batch). An upcoming version lets you opt to
"preserve UNIDs" when copying a selection or collection of docs to another db,
including more than Notes' limit of 2335 docs.

Another way to make a non-replica copy with preserved UNIDs is to make a
replica of the db, then with a couple clicks of NoteMan Toolbar change the
ReplicaID. Now you have a full non-replica copy with all the original UNIDs
(and signatures!) intact.
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
Ytria's ScanEZ has both the change ReplicaID and Change UNID function, and also
preserves UNIDs (it doesn't ask though) when doing a batch copy of documents
between databases. I don't know what the document limit might be, if any.

I've also recently found some API Lotusscript code over on the Breaking Par
site for changing Replica IDs. So that might be an option too:
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
Although you can certainly do this, I'm not sure that I'd recommend it unless
you really know what you're doing and there is absolutely no other way of
working around the issue. I've seen it used a couple of times by people who
maybe didn't fully understand the implications of what they were doing and it
caused really serious problems with the application replication.

But I agree it is very cool to use when you need to.

Also used in the personal Calendar to "Import Holidays"By Kevin Pettitt on 07/06/2008 at 03:18 PM EDT
I discovered that the Import Holiday agent used this technique of forcing a
specific UNID on a specific holiday when a the agent failed for user on a
specific holiday. Turns out the part of the agent that clears out the previous
entries missed one because that document had lost some of the field items that
allow the agent to find it. So everything blew up when it started repopulating
and got a unid conflict.

Once I figured out which holiday it was, I could create a view to select for
just that UNID, and the stray doc popped up.

Lesson there was to trap for that error (4091) and then go grab the existing
document with that unid, kill it, and then pick up from there.

In the meantime I've already put Nathan's upcoming trick into a client
application (I got a sneak peak too), and it works great. :-)
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
This code does not take into account response documents. If you change the
parent UNID the child document will no longer be associated with its parent.
Some simple recursive code to find the and update the response documents with
the parent UNID is needed to tackle this issue.
You are absolutely mistaken.By Andrew Pollack on 07/11/2008 at 09:42 AM EDT
This code will copy all documents, parent and child. The child will have a
$REF field on it that contains the UNID of the parent. When the code runs,
both the child and parent will retain their original UNID in the new database,
and thus the $REF field will properly reference the parent.

On top of that, I've tested this code and it worked perfectly with a full
response tree.
re: You are absolutely mistaken.By John Marshall on 07/11/2008 at 10:46 AM EDT
My bad, didnt read it properly as usual sorry. Your not changing the guid so
I'm an idiot.
re: You are absolutely mistaken.By John Marshall on 07/11/2008 at 10:48 AM EDT
I normally create an a Simple agent and use "Copy To Database" to keep guids
the same.

Other Recent Stories...

  1. 05/05/2016Is the growing social-sourced economy the modern back door into socialism?Is the growing social-sourced economy the modern back door into socialism? I read a really insightful post a couple of days ago that suggested the use of social network funding sites like “Go Fund Me” and “Kickstarter” have come about and gained popularity in part because the existing economy in no longer serving its purpose for anyone who isn’t already wealthy. Have the traditional ways to get new ventures funded become closed to all but a few who aren’t already connected to them and so onerous as to make ...... 
  2. 04/20/2016Want to be whitelisted? Here are some sensible rules for web site advertisingAn increasing number of websites are now detecting when users have ad-blocking enabled, and refuse to show content unless you "whitelist" their site (disable your ad-blocking for them). I think that is a fair decision on their part, it's how they pay for the site. However, if you want me (and many others) to white list your site, there are some rules you should follow. If you violate these rules, I won't whitelist your site, I'll just find content elsewhere. 1. The total space taken up by advertisements ...... 
  3. 12/30/2015Fantastic new series on Syfy called “The Expanse” – for people who love traditional science fiction[] “The Expanse” is a new science fiction series being broadcast onthe Syfy channelthis winter. It’s closely based on a series of books by author James S. A. Corey beginning with “Leviathan Wakes”. There are 5 books in the “Expanse” series so far. If you’re a fan of the novels you’ll appreciate how closely the books are followed.TIP: The first five episodes are already available on If you’re having trouble getting into the characters and plot, use those to get up to speed.The worlds created for ...... 
  4. 10/20/2015My suggestion is to stay away from PayAnywhere(dot)com  
  5. 08/07/2015Here is one for you VMWARE gurus - particularly if you run ESXi without fancy drive arrays 
  6. 08/06/2015The Killer of Orphans (Orphan Documents) 
  7. 06/02/2015Homeopathic Marketing: Traveler on my Android is now calling itself VERSE. Allow me to translate that for the IBM Notes community... 
  8. 03/17/2015A review of British Airways Premium Economy Service – How to destroy customer goodwill all at once 
  9. 02/26/2015There's a bug in how @TextToTime() and @ToTime() process date strings related to international standards and browser settings. 
  10. 01/21/2015Delivering two new presentations at Developer Camp (EntwicklerCamp) 2015 in Germany 
Click here for more articles.....

pen icon Comment Entry
Your Name
*Your Email
* Your email address is required, but not displayed.
Your thoughts....
Remember Me  

Please wait while your document is saved.