View member feedback to this tip.
This is a quick and easy-to-use code snippet that is very handy when you need to build a Revision History control in your application.
Please follow these four steps:
1. Create a new sub-form.
2. Create a computed field with a suitable title say, 'Revision_History'. Make sure it has the property 'Allow multiple values' checked.
3.The default value of the field must be this:
@If(@IsNewDoc; ""; Revision_History )
4.In the Query_Save event of the sub-form, paste the following code:
Sub Querysave(Source As Notesuidocument,
Continue As Variant)
Dim session As New NotesSession
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim reason As String
Dim whenNow As String
whenNow$ = Now()
If Val(Mid(whenNow, 10, 2)) > 12 Then
whenNow = Left(whenNow, Len(whenNow)-3)
End If
Set uidoc = workspace.CurrentDocument
If uidoc.IsNewDoc Then
reason = "Document created"
Else
reason = Inputbox$("Enter Details of Revision:")
If reason = "" Then
reason = "(no details given)"
End If
End If
Call uidoc.FieldAppendText( "Revision_History",
Chr(10) + WhenNow$ + " " + reason + "
(" + session.CommonUserName + ")")
End Sub
That's it. Save the sub-form and insert it in the form of your choice. Works great.
MEMBER FEEDBACK TO THIS TIP
For a really useable version history log, give users the ability to see what changed. By extending this code, you can have something really useful.There are two relatively easy ways to do this, depending on the level of detail desired.
1. List the fields that changed. Get a handle to the back-end docs, walk the fields, and build a list of the ones that have changed.
2. Provide a means of determining which fields should be monitored, and compare those fields. A profile doc works well, and you can use script to build a list of forms in the db, and on form selection, get a list of the fields in the form for the user to choose from.
A further extension of this would be to allow the users to configure certain fields to keep a real revision history on, and capture the old values to a history.
B. Hawthorne
Do you have comments on this tip? Let us know.
This tip was submitted to the SearchDomino.com tip exchange by member Vijay Sreegiriraju. Please let others know how useful it is via the rating scale below. Do you have a useful Notes/Domino tip or code to share? Submit it to our bimonthly tip contest and you could win a prize and a spot in our Hall of Fame.