Sometimes when a Lotus Notes user gets married or divorced, her last name changes. When this happens, she receives a new Lotus Notes ID file with her new last name. Unfortunately, she may no longer have proper access to Lotus Notes documents because the documents still contain her old last name. This LotusScript utility solves that problem. It updates all documents in the Lotus Notes database with the employee's new last name.
Sub Initialize Dim s As NotesSession, dc As NotesDocumentCollection, doc As NotesDocument Dim sOldName As String, sNewName As String, bSave As Boolean sNewName = "Elin Woods" sOldName = "Elin Nordegren" Set s = New NotesSession Set dc = s.CurrentDatabase.AllDocuments 'check every document in the database Set doc = dc.GetFirstDocument While Not doc Is Nothing bSave = False Forall niItem In doc.Items 'Do not change special $ fields 'Only change AUTHORS, NAMES, READERS, TEXT, USERDATA, USERID If Left(niItem.Name,1) <> "$" And (niItem.Type = AUTHORS Or niItem.Type = NAMES Or niItem.Type = READERS _ Or niItem.Type = TEXT Or niItem.Type = USERDATA Or niItem.Type = USERID) Then If Instr (niItem.Text , sOldName) > 0 Then 'Change the name only if it exists anywhere in the field Call doc.ReplaceItemValue(niItem.Name, ReplaceText(niItem.Values, sNewName, sOldName)) bSave = True End If End If End Forall If bSave = True Then Call doc.Save(True, False) 'only save if changed Set doc = dc.GetNextDocument(doc) Wend End Sub Function ReplaceText(ValueList As Variant, sNewText As String, sOldText As String) As Variant Dim tmpValueList As Variant, sLeft As String, sRight As String Redim tmpValueList(Ubound(ValueList)) 'create temp array of values For i = 0 To Ubound(ValueList) 'check each value in array If Instr (ValueList(i), sOldText) > 0 Then 'does the old text value exist in this item? sLeft = Left(ValueList(i), Instr (ValueList(i), sOldText) - 1) 'left of old text sRight = Right(ValueList(i), Len(ValueList(i)) - Instr (ValueList(i), sOldText) - Len(sOldText) + 1) 'right of old text tmpValueList(i) = sLeft & sNewText & sRight 'replace old text with new text Else tmpValueList(i) = ValueList(i) End If Next ReplaceText = tmpValueList End Function
When you do the rename in the Admin client with the help of AdminP, the process will do this job for you. In the tip, the author renamed the person in all Reader and Author fields. The only thing you have to do is check in the ACL whether this option is set or not.
I would rather have the Lotus Notes database Advanced ACL setting for the administration server apply one of the actions to either modify all Readers and Authors fields or modify all Names fields that the administration server should process. Having this set and using the standard Administration Process (AdminP) will achieve the same result without any programming. As developers, we never know when a name will change, so using AdminP and the correct ACL setting is the best way to go.
Do you have comments on this tip? Let us know.
Related information from SearchDomino.com:
This tip was submitted to the SearchDomino.com tip library by member Scott Huyser. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.
This was first published in February 2007