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.


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 (http://www.NoteMan.com) 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:
http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256FF200556ED1
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.

Matt
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. 01/26/2023Better Running VirtualBox or VMWARE Virtual Machines on Windows 10+ Forgive me, Reader, for I have sinned. I has been nearly 3 years since my last blog entry. The truth is, I haven't had much to say that was worthy of more than a basic social media post -- until today. For my current work, I was assigned a new laptop. It's a real powerhouse machine with 14 processor cores and 64 gigs of ram. It should be perfect for running my development environment in a virtual machine, but it wasn't. VirtualBox was barely starting, and no matter how many features I turned off, it could ...... 
  2. 04/04/2020How many Ventilators for the price of those tanks the Pentagon didn't even want?This goes WAY beyond Trump or Obama. This is decades of poor planning and poor use of funds. Certainly it should have been addressed in the Trump, Obama, Bush, Clinton, Bush, and Reagan administrations -- all of which were well aware of the implications of a pandemic. I want a military prepared to help us, not just hurt other people. As an American I expect that with the ridiculous funding of our military might, we are prepared for damn near everything. Not just killing people and breaking things, but ...... 
  3. 01/28/2020Copyright Troll WarningThere's a copyright troll firm that has automated reverse-image searches and goes around looking for any posted images that they can make a quick copyright claim on. This is not quite a scam because it's technically legal, but it's run very much like a scam. This company works with a few "clients" that have vast repositories of copyrighted images. The trolls do a reverse web search on those images looking for hits. When they find one on a site that looks like someone they can scare, they work it like ...... 
  4. 03/26/2019Undestanding how OAUTH scopes will bring the concept of APPS to your Domino server 
  5. 02/05/2019Toro Yard Equipment - Not really a premium brand as far as I am concerned 
  6. 10/08/2018Will you be at the NYC Launch Event for HCL Domino v10 -- Find me! 
  7. 09/04/2018With two big projects on hold, I suddenly find myself very available for new short and long term projects.  
  8. 07/13/2018Who is HCL and why is it a good thing that they are now the ones behind Notes and Domino? 
  9. 03/21/2018Domino Apps on IOS is a Game Changer. Quit holding back. 
  10. 02/15/2018Andrew’s Proposed Gun Laws 
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.