Some connected posts from Nathan Freeman, Andrew Pollak, and Andrei Kouvchinnikov talk about the ability to set the Universal ID of a document. This is pretty cool stuff. So I thought it would be a worthwhile extension of the .Domino Framework to support this capability. As is my way, I have stolen some of the code and ideas to support the updating of the Document UNID.
The Document UIND in the new Inspector tool is now read/write. Simply type in a new UNID over the top of the existing value displayed, click save and the document will be assigned a new UNID. Note: Because the save creates a new document, the original document is deleted (for which you need delete rights to the database).
I have also extended the DominoDocumentCollection class to implement some of Nathan's ideas:-
A new MakeResponse method has been added. This acts similar to the NotesDocument.MakeResponse method, except that it makes all documents in a collection the response documents for a nominated parent odcument.
A new CreateNewDocumentKey method has been added. This takes as an argument a field name to be used as the key. A new UNID is calculated based upon the value of the provided field (1st item for lists). To minimize issues with response documents the MakeResponse method is called so that all reponse documents are now linked to the new UNID.
'/**
' * Creates new UNIDs based upon a key value. This supports faster lookup of documents by key (as per Nathan Freeman)
' */
Sub CreateNewDocumentKey(KeyField As String)
Dim NewUNID As String
Dim UNID As String
Dim CommandString As String
Dim Result As Variant
Dim NextDoc As NotesDocument
Dim Children As baseDominoDocumentCollection
Dim OriginalDoc As NotesDocument
On Error 4091 Resume Next
Set Doc = iDocumentCollection.GetFirstDocument
While Not Doc Is Nothing
Set NextDoc = iDocumentCollection.GetNextDocument(Doc)
If Doc.HasItem(KeyField$) Then
UNID$ = Doc.UniversalID$
CommandString$ = @Password">|@Password("| + Cstr(Doc.GetItemValue(KeyField)(0)) + |" )|
Result = Evaluate(CommandString$)
NewUNID$ = Mid$(Result(0),2,32)
If NewUNID$ <> UNID$ Then ' Document already keyed on this value
Doc.UniversalID = NewUNID$
Call Doc.Save(True,False)
If Err = 0 Then ' Indicates document UNID already exists
Set OriginalDoc = Doc.ParentDatabase.GetDocumentByUNID(UNID$)
If OriginalDoc.Responses.Count > 0 Then
Set Children = New baseDominoDocumentCollection(OriginalDoc.Responses)
Call Children.MakeResponse(Doc)
End If
Call OriginalDoc.Remove(True)
End If
End If
End If
Set Doc = NextDoc
Wend
End Sub