Tip

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
6:17pm
' --------------------------------------------------------------------
---------------------------------------------------------

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)
Else
' New items appear at the top of the history field
If item.text = "" Then
' Handle a current history item with just a single NULL
value.
Redim newHistory(0) As String
Else
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)
Next
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
field
' 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

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
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
Sort by: OldestNewest

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:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.