Tracking All Field Changes via Lotus Script

Hi,

I am using some code that I found on the Forum to track all the Field changes in a document by putting comment in History section. It works pretty well except for 2 data types - dates and Rich Text.

If a value is in a Date field then it ALWAYS generates an entry for that field even if the field has NOT been changed. The debugger shows both old and new values to be exactly the same.

For Rich Text - it NEVER generates an entry when altered. In the debugger, it is getting the old value from the front end AND the back end, so it thinks there is never a change. I have tried a computed field with Abstract formula and same result.

Other than those two cases the code catches all the other field changes.  Here is my code for review. Hopefully, someone can shed some light on how to make this work.

Sub Querysave(Source As Notesuidocument, Continue As Variant)

Dim session As New NotesSession

Dim ROSIview As NotesView

Dim originalDoc As NotesDocument

Dim whichField As String

Dim newValue As String

Set db = session.Currentdatabase

Set doc = source.Document





If Not source.IsNewDoc Then

	Set ROSIview = db.getview("vwLkupByUNID")		

	Set originalDoc = ROSIview.GetDocumentByKey (Doc.UniversalID)   'Get handle on unchanged backend doc by using UNID. 

	

	Forall field In doc.Items                           'Search thru all fields checking for any changes made.

		whichField = field.name

		newValue = Cstr (field.text)                   'Get value in front-end field so can compare to determine if it has been changed.



			If (Left(whichField,1) <> "$") Then                      'Skip all reserved fields beginning with "$".

				oldValue = Cstr (originaldoc.GetitemValue( whichField )( 0 ))                              'Get field in backend that has not been changed yet.

				If oldValue <> newValue Then                                                                         'Compare backend value with frontend value and add entry when they are not the same.

					entry = Chr$(10) + Now() + "   " + session.CommonUserName +	"  changed  " + whichField + "  from  " + oldValue + "  to  " + newValue

					Call source.FieldAppendText("History",";"+entry)

				End If	

			End If

		End If

	End Forall

End If

'*** END OF CODE TO TRACK FIELD CHANGES.

End Sub

Thanks for any help,

Tim

Subject: Tracking All Field Changes via Lotus Script

For rich text, use getformattedtext

Your date fields are probably also storing the time, which is why they’re always changing. Try comparing only the time component.

Use the type attribute of item to determine what type of field you’re looking at.

Subject: RE: Tracking All Field Changes via Lotus Script

With date/time fields, there’s also the possibility that the field’s date text format isn’t the same as what Cstr() will return (the system default short date and time). Frankly, comparing the back-end values rather than trying to compare the text in the front end to the text-ified back end value would be a better idea unless you are working in a single application and can guarantee that the front-end date format (field) settings will never change.

Subject: Still looking for help in resolving getting Front end Rich Text value

Everyone,

Thanks for your recommendations.

An update - I think Saul's suggestion for the Date field will work. I experimented with it in Time fields and the code executed correctly.



Still need some help with the Rich Text.  This code



        newValue = CStr(field.text)



is getting a value - but it is the OLD backend value.  For other values it retrieves the front end value (which is new). By the way, getFormattedText did not make a difference in the Rich Text value. In all scenarios thus far, the retrieved Front end value is same as retrieved back end value.



Any ideas on why this happens or how to make it get the correct front end value for Rich Text.

Thanks,

Tim

Subject: Have you just considered using Notes versioning?

Subject: RE: Have you just considered using Notes versioning?

I am not familiar with using Notes versioning to capture changes at the Field level.

Would you elaborate or provide a link to some source that gives more detail on tracking field changes via versioning?

Thanks,

Tim

Subject: RE: Have you just considered using Notes versioning?

It basically just creates responses as copies of the original document.https://www.ibm.com/support/knowledgecenter/SSVRGU_9.0.1/basic/H_ABOUT_TRACKING_VERSIONS_OF_A_DOCUMENT.html

Subject: Versioning not good solution in this app.

Thank you for this suggestion, but would not want to fill database with lots of extra documents.