Update a field in all Lotus Notes documents using a Lotus Notes agent

SearchDomino.com member Mick Crowder provides a Lotus Notes agent that will allow you to update a specific field in all selected Lotus Notes documents with new data.

VIEW MEMBER FEEDACK TO THIS TIP

With this Lotus Notes agent, you'll be able to update a specific field in all selected Lotus Notes documents with new data.

  
'Declarations:
Dim session As NotesSession
Dim ws As NotesUIWorkSpace
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim FieldName As String, NewValue 
As String, Message As String Dim item 
As NotesItem Dim YesNo As Variant Dim i As Integer

'Initilaize:
Sub Initialize
Dim session As New NotesSession
Set ws = New NotesUIWorkSpace
Set db = session.CurrentDatabase
Set dc = db.UnprocessedDocuments
Set doc = dc.GetFirstDocument 
FieldName = Inputbox$("Enter Field Name.  
Enter this value very carefully.  
Spelling counts.","Enter Field")
If FieldName = "" Then Exit Sub 
NewValue = Inputbox$("Enter the new value.  
Enter 'Quit' to abort.","Enter Value")
If NewValue = "Quit" Then Exit Sub
Message = "Field Name: " & FieldName & Chr$(13) & _
"New Value: " & NewValue & Chr$(13) & _
"Records to be Updated: " & 
Cstr(dc.Count) & Chr$(13) & Chr$(13) &_
"Do you wish to continue?"
YesNo = Messagebox(Message,36,"Continue?")
If YesNo = 7 Then Exit Sub
For i = 1 To dc.Count
Set doc = dc.GetNthDocument(i)
Set item = doc.ReplaceItemValue(FieldName,NewValue)
Call doc.Save(True, True)
Next
End Sub

MEMBER FEEDBACK TO THIS TIP

This tip is overly complex. It ignores a simpler, method already available in the documentcollection class.

Call dc.StampAll(FieldName,NewValue)

—Gene K.

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

Don't forget that the NotesDocumentCollection.GetNthDocument gets extremely slow when the number of documents in the NotesDocumentCollection is large.
—Rhodri H.

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

This tip was submitted to the SearchDomino.com tip library by member Mick Crowder. 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 last published in August 2006

Dig Deeper on Lotus Notes Domino Agents

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

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 ...

SearchDataCenter

SearchExchange

SearchContentManagement

Close