Document History Function

I found that in many of my applications I was always recording document history
(creation, changes, workflow events, etc.) in a multi-value text field usually
at the bottom of the document. Most of the time I took the easy way out and
just kept appending history items to the field, this results in a oldest to
newest list. Most often users want a list that is most recent (newest) to
least recent (oldest). I wrote the WriteHistory function to accomondate both
types of history lists. The ReverseMVI (Reverse Multi-value item) was written
to correct my past mistakes and reverse the order of exisitng histroy lists.
Function WriteHistory(historyText As String, mode As Integer, historyItem
As String, doc As NotesDocument) As Integer
' --------------------------------------------------------------------
' historyText - The text string to be written.
' mode - 0 = new item appended to the bottom of the list. 1 = new item
is added at the top of the list.
' HistoryItem - string name of the item to add the historyText to.
' doc - the NotesDocument that contains the history item.
' --------------------------------------------------------------------
' Time Stamps in a mmm d,yyyy h:mmam/pm format such as Oct 11,1999
' --------------------------------------------------------------------

Dim stampDate As String
Dim stampTime As String
Dim item As NotesItem
Redim newHistory(0) As String
Dim x As Integer

' Date/Time Formats
stampDate = "mmm d,yyyy"
stampTime = "h:nnam/pm"

Set item = doc.GetFirstItem(HistoryItem)
If item Is Nothing Then
' Just in case the item does not already exist on the document
Set Item = New NotesItem( doc, HistoryItem, "")
End If

If mode = 0 Then
' New items appear at the end of the history field
Call item.AppendToTextList(Format(Date(),stampDate) & " " &
Format(Time(),stampTime) & " - " & HistoryText)
' New items appear at the top of the history field
If item.text = "" Then
' Handle a current history item with just a single NULL
Redim newHistory(0) As String
Redim newHistory(Ubound(item.values)+1) As String
' Transfer previous history entries
For x = 0 To Ubound(item.values)
newHistory(x+1) = item.values(x)
End If
' Add the new history entry
newHistory(0) = Format(Date(),stampDate) & " " &
Format(Time(),stampTime) & " - " & HistoryText
' Rewrite the hsitory list
item.values = newHistory
End If

WriteHistory = True

End Function

Function ReverseMVI(itemName As String, doc As NotesDocument) As Integer
' --------------------------------------------------------------------
' This function will reverse the order of the values in a multi value
' itemName - Field Name of the history list to reverse.
' doc - The notes document object in which the itemName field exists.
' Example: Original values... 1,2,3 After ReverseMVI... 3,2,1
' --------------------------------------------------------------------
Dim item As NotesItem
Dim nEntries As Integer
Redim newHistory(0) As String

Set item = doc.GetFirstItem(itemName)

nEntries = Ubound(item.values)
Redim newHistory(nEntries) As String
Forall v In item.values
newHistory(nEntries) = v
nEntries = nEntries - 1
End Forall

item.values = newHistory

ReverseMVI = True

End Function

This was first published in November 2000

Dig Deeper



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:




  • iSeries tutorials'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 ...