OpenNTF.org - History Class for documents
    Advanced
   OpenNTF Code Bin
Edit Document Code By Date > Code Document
About This Code
Brief Description:
History Class for documents 
Rating:
Rating: 5 , Number of votes: 5 
Contributor:
Michael Woehrer 
Category:
Lotusscript 
Type:
Document Management 
Notes Version:
R5.x, R6.x, R7.x 
Last Modified:
14 Mar 2006 
OpenNTF Disclaimer

All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.

Code / Description
Updated on March 14, 2006

Purpose

Usually, a document history/logging doesn’t tell you very much about what was being changed in the document:



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


Implementation / Frequently Asked Question / etc.

http://www.sw-guide.de/projekte/lotus-notes-projekte/lotusscript-history/


Download

http://www.sw-guide.de/projekte/lotus-notes-projekte/lotusscript-history/
Usage / Example
 Comments
Posted by Hans Petter Johanson on 10/16/2004 02:13:07 PMvItemNamesArray
As I am brand new to Notes Design... I need help to implemnt the vItemNamesArray info into the Form or History field...
I have been looking for this functionality for days and this script would suit med perfectly if I can implement it.
Posted by Michael Woehrer on 10/17/2004 05:10:24 AMRe: vItemNamesArray
Hans Petter,

The easiest way is to create this array directly in the PostOpen event of the form above the two lines mentioned in 2-c (Set g_history ........).

Example:
---------------------------------------------------------------------
Dim vItemNamesArray(3) as String
vItemNamesArray(0) = "Subject"
vItemNamesArray(1) = "Date"
vItemNamesArray(2) = "Body"
vItemNamesArray(3) = "Remarks"
Set g_history = New History
Call g_history.PostopenStartObservation(Source, vItemNamesArray)
---------------------------------------------------------------------

Subject, Date, Body and Remarks are field names of your form. These fields will be observed by the history class.


Another possibility would be to use a database setup document (can be a profile document) and put the item names into a textfield (allow multiple values). Then you need to readout the content of this field in the PostOpen-event.

Example when using a profile document:
---------------------------------------------------------------------
Dim vItemNamesArray as Variant
Dim docProfile As NotesDocument
Set docProfile = db.GetProfileDocument("($Preferences)")
vItemNamesArray = docProfile.HistoryItems
Set g_history = New History
Call g_history.PostopenStartObservation(Source, vItemNamesArray)
---------------------------------------------------------------------
Posted by Hans Petter Johanson on 10/17/2004 07:51:51 AMPerfect!
The latest info was very helprful. The log is working perfectly! Many Thanks Michael!
Posted by Bob Clough on 11/12/2004 03:35:48 AMPossible add in
This is a really nice bit of code. 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.
Posted by Michael Woehrer on 11/12/2004 10:53:03 AMRe: Possible add in
Bob,
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 MaxChanges

You also do have the possibility to change this for every history object you create via the Property 'MaxChanges'.
But I assume you need this globally, so just change the constant HIST_MAXENTRIES.

Please note that we do have a limit in Notes/Domino regarding text-items (maximum 64,363 characters). Therefore I 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.

Hope this helps,
Michael
Posted by Bob Clough on 11/12/2004 11:16:58 AMToo cool for school!
I should've guessed you had this covered ;-)
Posted by Alain H Romedenne on 11/25/2004 03:13:11 AMExcellent Job & few remarks..
I would raise an exception with R4 ( PostSave is new with R5 )
I would remove PostSave event handling when switching from/to Edit to/from Read mode
History class sample is paving way to "Observer" & "Command" design patterns enablement:
1. One may decouple UI / Storage aspects with the Observer pattern
1. One may offer Undo/Do (Command pattern) while multiple saves are performed during a document editing session
For example I'd go for :
a front-end HistoryUIListener class name hooking necessary NotesUIDocument events
+ registerObserver( obj : iHistoryObserver )
+ unregisterObserver( obj : iHistoryObserver )
an optional iHistoryObserver interface class declaring a PostSave method.
+ PostSave( source : NotesUIDocument )
my application back-end class name implementing iHistoryObserver interface
+ PostSave( source : NotesUIDocument ) where history is built.. doc, historyName, itemNames
Pros
Such removes 'History' field harcoding from History class
Such enables to have multiple 'History' fields in a NotesDocument
...
Be that as it may History class is an perfect sample
Alain Romedenne
Posted by Michael Woehrer on 11/27/2004 12:46:22 PMRe: Excellent Job & few remarks..
Many thanks for your helpul suggestions, Alain.

I'll come back to you as soon as I have time to rework my history class.

Regards,
Michael
Posted by Davy E Czarnecki on 06/29/2005 03:44:30 PMTabs in the history field
First, this class is excellent and a big time saver. I just had one question. I am using the 6.02 client. I am seeing a problem with the tabs when multiple edits are being observed:
29.06.2005 - 15:31 David Czarnecki Document created.
29.06.2005 - 15:31 David Czarnecki Changed field 'One' (former: 'One')
29.06.2005 - 15:32 David Czarnecki Changed field 'One' (former: '1')
29.06.2005 - 15:32 David Czarnecki Changed field 'One' (former: '2')
Changed field 'Two' (former: 'n/a')
Changed field 'Three' (former: 'n/a')
Am I missing something?
Thanks in advance,
Davy Czarnecki
Posted by Ravi Sinha on 12/08/2005 01:09:34 AMStrange Behaviour of the Above Functionality
I have tried this Code. It works fine when I execute in a Debug Mode.
But If I execute it normally, It doesn't work.
Could you tell me what may be the problem? Its really strange but wonderful when it works.
Posted by Davy E Czarnecki on 12/08/2005 11:08:46 AMPossible solution for history class only working in Debug
I had the same issue. The history class was working in another form in the database just fine. However, in one form, the history was only being updated in debug mode. After troubleshooting the issue for a while, I found out that in the globals declaration of the form, there was Option Compare NoCase statement. Taking this out corrected the issue.
Posted by john smick on 12/09/2005 12:36:50 PMHistory Table Tab Alignment
I'm having a heckuva time getting the data to align with the table column headers. Using a single Char9 tab does not provide enough width to the columns (e.g. a long username will wrap). Can you provide more detail about how to implement the table as it is shown in the screen capture? I have a two row table with the header in row one and three columns. The history field is below in a single spanned cell. I can make these align but it's not very precise, nd if I Change two fields during the session, the second field does not record the date and user, it only records the third column data which is not aligned to the third column (it's under the second.) Thanks much!
Posted by john smick on 12/11/2005 08:46:53 PMPossible Fix for tab Issue
Create a table 1x1
Inside the table, at the top, create another table 1 row 3 columns. This is your header ■ set it up accordingly (date, name, action).
Put your history field below your header table, but still inside the 1x1 table.
Turn on the ruler, click on the history field, and set the tabs to match the header columns. This is where it gets fudgy - I have my change history table inside a still larger tabbed table, so my tabs don't align exactlry with the header table columns. They're off by quite a bit in designer, but in the client the alighn just fine. You will have to play with this and fine tune it.
The problem occurs when the header and the history field are part of the same table. Hope this helps.
Posted by Joshua A Hesson on 04/25/2006 09:33:43 AMimporting the lotusscript
when i imported the lotusscript into a new script library, it imports everything into the Declarations...is that where it should be? when i run through it with the debugger, i get several errors, here is one...
"Run-time error --- procedure: <PROCESSPOSTSAVE>, error #200 (Attempt to access uninitialized dynamic array), line #311"
any help is greatly appreciated!
Posted by Arshad Mehmood on 05/10/2007 10:57:40 AMHow to Use this class on Web
Anybody have an idea if I can use this class for my web Application?. I copied the Postevent code into agent and called it on webqueryopen but it did not work.
Any ideas??
Regards
Arshad
Posted by Rob Pinion on 06/05/2008 04:26:55 PMModified to show new as well as old value
[a href="http://www.openntf.org/projects/codebin/codebin.nsf/CodeByDate/EE37F78B88FF57B58625745F0075A1D9?OpenDocument">Here</a> is a modification of the code to show the new and old values. Someone had asked for this out on Michael's site at one point. Easy enough.
Posted by Rob Pinion on 06/05/2008 04:27:44 PMOops
[<a href="http://www.openntf.org/projects/codebin/codebin.nsf/CodeByDate/EE37F78B88FF57B58625745F0075A1D9?OpenDocument">Here is a better link</a>]. Sorry about that.
Posted by Rob Pinion on 06/05/2008 04:28:58 PMDarn no HTML!!
Well, HTML worked when I posted a link in the code bin back to this site. Here it is so you can copy and paste. Also OpenNTF isn't allowing me to remove/edit my previous comments.
http://www.openntf.org/projects/codebin/codebin.nsf/CodeByDate/EE37F78B88FF57B58625745F0075A1D9?OpenDocument
 Add your comment!