Usually, a document history/logging doesn’t tell you very much about what was being changed in the document:
This history class observes changes of a UI document and writes these changes into a history field.
In addition, you can use this class to add an entry in the backend (e.g. if you change the status of a document via Lotus Script) or to empty the history field.
The history class can be implemented in 6 easy steps:
- Download and unzip the file, create a new scipt library, import it via „File / Import…“ and save it by using an appropriate name, e.g. â€œClassHistoryâ€.
- Open the form in that you want to add the history and create a table or text (separated by tabs) which will be the header of the history:
Date | User | Changes
- Place a new field (field name e.g. ‚History‘) below the header: type ‚Text‘, allow multiple values, ‚computed when composed‘, ‚display separate values with ‚-New Line-‚.
- Add the following code in the Global Options of the form:
- In the form’s Global Declarations, add the following line of code:
Dim g_history As History
- Enter the following code in the PostOpen event:
' The strItemsArray contains the field names you want to observe. Dim strItemsArray(2) As String strItemsArray(0) = "Subject" strItemsArray(1) = "Date" strItemsArray(2) = "Body" ' The strItemDspArray contains the field names that are displayed, ' if you do not want to use different display names, then just pass strItemsArray ' as 3rd parameter to the PostOpenStartObservation method. Dim strItemDspArray(2) As String strItemDspArray(0) = "The Subject" strItemDspArray(1) = "Last modified on" strItemDspArray(2) = "Content" ' intMaxLenEntryArray is the maximum length of each value being displayed. ' Provide an empty array if you do not want to limit this. ' Here we limit each value to 75 chars max. Dim intMaxLenEntryArray(2) As Integer Dim i As Integer For i = 0 To 2 intMaxLenEntryArray(i) = 75 Next ' "History" is the name of the history field. Set g_history = New History("History") ' Now we call the initial method of this History object Call g_history.PostopenStartObservation(Source, strItemsArray, strItemDspArray, intMaxLenEntryArray)
That’s it, after saving the form, the history class should work.
For additional methods and properties see the source code of this class.
Please note that the method ‚PostopenStartObservation‘ also observes
a) the event ‚QueryModeChange‘ for changing the document from read mode to edit mode.
b) the event ‚PostSave‘ for saving changes to the item ‚History‘.
Frequently Asked Questions and Known Issues
- Question: Would it be possible to amend it so that the max entries setting meant that the last 20 edits would be retained? So the oldest entry dropped off each time a new one was added.
Answer: You can change this behavior very easy:
Open the script library and switch to the „Options“. At the bottom there is the section ‚CONSTANTS‘. Change the following Integer (20) to a value you need, e.g. 20000:
Const HIST_MAXENTRIES% = 20 'Maximum entries in the history. You can change this value via the Property MaxEntries
You also do have the possibility to change this value for every history object you create via the Property ‚MaxEntries‘.
Please note that we do have a limit in Notes/Domino regarding text-items (maximum 64,363 characters). Therefore I’ve implemented a second constant (HIST_MAX_SIZE_CHARS). So even if you allow 20000 history entries (HIST_MAXENTRIES), this class will drop off the oldest entries to avoid a breakage of this limit if you reach 60,000 chars in your history text-field.
- Question: I have a form in an ND7 database that only seems to log changes using the history class when I debug it. If I turn off the debugger and try to make changes none get logged. It’s the strangest thing. I use the code in the same database in a different form and it works great.
Answer: In the „PostOpenStartObservation“ sub (that is usually called in the Post Open event of a form), there is the following code:
On Event Querymodechange From m_uidoc Call ProcessQuerymodeChange
I am using this to avoid using extra code in the QuerymodeChange event. In some circumstances, this does not work for some unknown reasons (Notes bug?).
To solve this issue, comment out this line and add a code in the Querymodechange event of the form:
Call History.ProcessQuerymodeChange(Source, Continue)
Since this sub is private, you need to change it in the history class from from private to plublic:
Private Sub ProcessQuerymodeChange(Source As NotesUIDocument, Continue As Variant)
Public Sub ProcessQuerymodeChange(Source As NotesUIDocument, Continue As Variant)
- Question: «I’m getting the error message ‚Subscript out of range’» OR «Not all of the mentioned fields are being logged».
Answer: Check the arrays in the PostOpen event of the form. Also, note that the default for array indexes in LotusScript is 0 based and not 1 based.
- Question: I am experiencing crashes on ND 6.5.3 once in a while, e.g. when using the preview pane.
Answer: Thomas Schulte has reported a possible workaround (function
- Remove the line
Dim vitemvaluesArray() as variant.
Redim vItemvluesArray(intItems) as string.
- Remove the line
Terms and conditions
You can use, redistribute and/or modify this class under the terms of the SOFTWARE GUIDE LICENSE.
This history class is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the SOFTWARE GUIDE LICENSE for more details.
By downloading this software, you are accepting these terms and conditions.
Do you like my work? Any donation would be highly appreciated.
Version History and Changelog
- 1.5 [2005-03-16] – published on 2006-03-14:
Bug fix: In method AddEntry: update initial value of history item (needed if this method is used in a form with active observation; this avoids discarding of AddEntry if fields have been changed)
Feature: New method AddEntry2
Feature: PostopenStartObservation: vItemNamesDspArray and vMaxEntryLenArray added
- 1.4 [2005-01-30]:
Bug fix: An error occurred if a new doc was created and then saved for more than one time without closing it.
- 1.3 [2004-11-28]:
Feature: Removed hardcoded item name for history-item, now we provide the item name when instantiating the new history object
Bug fix: If you saved a document several times during editing without closing it, the history was written on every save. Now we do always compare with the initial values. This avoids useless multiple entries for one and the same field.
- 1.2 [2004-10-17]:
Bug fix: A right parenthesis „)“ was wrongly added to the end of an entry if an rtf changed
Buf fix: Some functions were ‚public‘ and not ‚private‘
- 1.1 [2004-10-10]:
Feature: Now easier implementation of this class (PostOpen is the only event you need)
Feature: New property „MaxEntries“
- 1.0 [2004-10-01]:
As of 01/18/06, I have enabled comments on this page, feel free to post below any queries you have regarding this class (your e-mail address is required, but will not be published) – in English or German.