Document History Using Arrays Vs List Items

This is very useful for auditing documents and tracking changes. Here is an
easier way to store items in a list without using arrays. I used it to create
a list of all the editable field values on a document to later compare these
values with the current values to store what has changed in the document since
the last save. I then use this info to create a brief document history. You
can change the script around to meet your specific auditing needs.
'Within the Post Open Event I call a routine from my Script Library to first
store all editable field values in the document.

Sub StoreEditFields

Dim Ws As New NotesUIWorkspace
Dim UiDoc As NotesUiDocument
Dim Doc As NotesDocument
Dim FieldValue As Variant
Dim FieldName As Variant

Set UiDoc = Ws.CurrentDocument
Set Doc = UiDoc.Document

Forall Values In Doc.Items
FieldName = Lcase(Values.Name)
FieldValue = Doc.GetItemValue(Values.Name)
ItemList(FieldName) = FieldValue(0)
End Forall

End Sub

'Within the Query Save Event I call another routine from my Scrpt Library to
compare all stored values to current values in document flagging the ones that
have changed. This will then create my document history entry.

Function CheckEditFields(EditFlag)

Dim Ws As New NotesUIWorkspace
Dim UiDoc As NotesUiDocument
Dim Doc As NotesDocument
Dim FieldValue As Variant
Dim FieldName As Variant

Set UiDoc = Ws.CurrentDocument
Set Doc = UiDoc.Document

Forall Values In Doc.Items
FieldName = Lcase(Values.Name)
FieldValue = Doc.GetItemValue(Values.Name)
If Iselement( ItemList(FieldName) ) Then
If FieldValue(0) <> ItemList(FieldName) Then
EditFlag = True
End If
End If
End Forall

End Function

'To create your Document History entry, you must first creat a multivalued text
field on your form to hold the History text. Then in the Query Save event,
based on the above Editflag enter this code:

Set Item = Source.Document.GetFirstItem("History")
i = 0
Forall Values In Item.Values
i = i + 1
Redim Preserve HistoryArray(1 To i)
HistoryArray(i) = Values
End Forall

'If you want to add what was changed pull the value from itemvalue above and
place it in this string
AuditHistory = "Updated By " & Session.CommonUserName & " on " & Now

If Source.Document.History(0) <> "" Then
Redim Preserve HistoryArray(1 To Ubound(HistoryArray) + 1)
End If
i = Ubound(HistoryArray)
HistoryArray(i) = AuditHistory
Call Source.Document.ReplaceItemValue("History",HistoryArray)

Dig Deeper on LotusScript

Join the conversation

1 comment

Send me notifications when other members comment.

Please create a username to comment.

Dwight,
What is the ItemList variable declared as?
Cancel

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com'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 ...

SearchDataCenter

SearchContentManagement

Close