Hi All. I modify existing code daily and notice poor methods that developers sometimes use to get things done.
In LotusScript, if you have a Document Collection, and for each of these documents, you want to set the field Status with a value of “Submitted”, the following seems to be the common approach:
Set NotesDocument = NotesDocumentCollection.GetFirstDocument
While Not( NotesDocument is nothing )
Call NotesDocument.ReplaceItemValue( “Status”, “Submitted” )
Call NotesDocument.Save( True, True )
Set NotesDocument = NotesDocumentCollection.GetNextDocument( NotesDocument )
Some might use For Loops, or Do While Loops instead of While-Wend, which doesn’t matter, because the good news is that there is a simple method that can replace the above code:
Call NotesDocumentCollection.StampAll( “Status”, “Submitted” )
Update on 13th September 2011
Hi Everyone. Thanks to “Lars Berntrop-Bos” for pointing out the following:
In version 8.5, IBM introduced another Method called “StampAllMulti” which works on both a NotesDocumentCollection and a NotesViewEntryCollection.
This function lets you use a NotesDocument Object as a Data Template for your Collection. All data in fields created in the NotesDocument Data Template will be sent through to the documents in the NotesDocumentCollection.
It will look something like this:
Set NotesDocument = NotesDatabase.CreateDocument
.FieldOne = “Value One”
.FieldTwo = “Value Two”
Call NotesDocumentCollection.StampAllMulti( NotesDocument )
Just 2 NOTES:
1. If the fields don’t exist in the Docs in the DocumentCollection, they will be created.
2. If the Data Types are not the same, the Data Type in your NotesDocument Data Template will take preference, and will overwrite the Data Type fields in the DocumentCollection.