How to update Lotus Notes documents after an employee last-name change

After a last-name change, a Lotus Notes user may no longer have proper access to Lotus Notes documents, because they still contain her old last name. This LotusScript utility from SearchDomino.com member Scott Huyser solves that problem. It updates all documents in the Lotus Notes database with the employee's new last name.

VIEW MEMBER FEEDACK TO THIS TIP

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

MEMBER FEEDBACK TO THIS TIP

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.
—Axel M.

******************************************

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.
—John T.

Do you have comments on this tip? Let us know.

Related information from SearchDomino.com:

  • FAQ: LotusScript advice
  • Learning Guide: LotusScript
  • Expert Advice: Name change and user didn't receive email to accept it
  • Reference Center: LotusScript tips and resources

    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

    Dig deeper on LotusScript

    0 comments

    Oldest 

    Forgot Password?

    No problem! Submit your e-mail address below. We'll send you an email containing your password.

    Your password has been sent to:

    -ADS BY GOOGLE

    SearchWinIT

    Search400

    • iSeries tutorials

      Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

    • V6R1 upgrade planning checklist

      When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

    • Connecting multiple iSeries systems through DDM

      Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

    SearchEnterpriseLinux

    SearchVirtualDataCentre.co.UK

    Close