I basically need a code how to keep track on which of the field had been changed by who and when - properly sorted in table will be best.
I post the same question before and a number of few very kind people attempted to help but not a “complete” solution as “we” manage to track only those static fields; i.e. if I got F1, f2, F3, no problem but I need it to apply to mostly of all forms and not to over see that from time to time, I might have new field name and also what about if the form has a lot of fields??? I was then being introduced to visit the www.openntf.org.
After so many days try, I couldn’t get what I want; always nearly close…
I’m sure this is something common that some Notes Developer will need.
Hope someone may provide me a COMPLETE CODE how to have a LotusScript (or JS / Java, I don’t mind) that can dynamically tell who, wehn and the fields (the content) that changed.
You will need to load the values of all of the fields when the document opens into an Array. Then in the Post Save event, check to see if any field values have changed. The code below actually creates a history document for a specified document, but you could easily change the code to add the table to the bottom of a document.
Dim doc As NotesDocument
Set doc = Source.Document
x = 0
Forall item In doc.Items
pos = Instr(item.name, "$")
If pos = 0 Then
Redim Preserve oArray(x)
oArray(x).name = item.name
oArray(x).value = item.values(0)
x = x + 1
End If
End Forall
End Sub
Sub Postsave(Source As Notesuidocument)
Dim doc As NotesDocument
Dim docchanged As Boolean
Dim bodyitem As NotesRichTextItem
Dim db As NotesDatabase
Dim view As NotesView
Dim s As New NotesSession
Dim histdoc As NotesDocument
Dim richStyle As NotesRichTextStyle
Set doc = Source.Document
Set db = s.CurrentDatabase
Set view = db.GetView("History Docs")
x = 0
docchanged = False
Forall item In doc.Items
pos = Instr(item.name, "$")
If pos = 0 Then
Redim Preserve nArray(x)
nArray(x).name = item.name
nArray(x).value = item.values(0)
x = x + 1
End If
End Forall
'Check For Changes
z = 0
For y = Lbound(oArray) To Ubound(oArray)
If oArray(y).value <> nArray(y).value Then
Redim Preserve hArray(z)
hArray(z).name = oArray(y).name
hArray(z).fromval = oArray(y).value
hArray(z).toval = nArray(y).value
z = z + 1
docchanged = True
End If
Next
If docchanged Then
Set histdoc = view.GetDocumentByKey(doc.UniqueKey, True)
If histdoc Is Nothing Then
Set histdoc = New NotesDocument(db)
With histdoc
.form = "History"
.OfficeLocation = doc.OfficeLocation(0)
.CostCenter = doc.CostCenter(0)
.UMA_Region = doc.UMA_Region(0)
.UnitNum = doc.UnitNum
.VinNum = doc.VinNum(0)
.ParentKey = doc.UniqueKey(0)
.Fname = doc.FName(0)
.LName = doc.LName(0)
.LicensePlate = doc.LicensePlate(0)
.Model = doc.Model(0)
.JobTitle = doc.JobTitle(0)
.VehicleType = doc.VehicleType(0)
End With
Set bodyitem = New NotesRichTextItem (histdoc, "Body" )
Set richStyle = s.CreateRichTextStyle
richStyle.Bold = True
richStyle.Underline = True
Call bodyitem.AppendStyle(richStyle)
Call bodyitem.AppendText(|FIELD NAME|)
Call bodyitem.AddTab(1)
Call bodyitem.AppendText(|Changed From|)
Call bodyitem.AddTab(1)
Call bodyitem.AppendText(|To|)
Call bodyitem.AddTab(1)
Call bodyitem.AppendText(|On|)
Call bodyitem.AddTab(1)
Call bodyitem.AppendText(|By|)
Call bodyitem.AddNewline(2)
richstyle.Bold = False
richStyle.Underline = False
richStyle.FontSize = 8
Call bodyitem.AppendStyle(richStyle)
For zz = Lbound(hArray) To Ubound(hArray)
Call bodyitem.AppendText(hArray(zz).name)
Call bodyitem.AddTab(1)
Call bodyitem.AppendText(hArray(zz).fromval)
Call bodyitem.AddTab(1)
Call bodyitem.AppendText(hArray(zz).toval)
Call bodyitem.AddTab(1)
Call bodyitem.AppendText(Today)
Call bodyitem.AddTab(1)
Call bodyitem.AppendText(s.CommonUserName)
Call bodyitem.AddNewline(1)
Next
Else
Set bodyitem = histdoc.GetFirstItem("Body")
Set richStyle = s.CreateRichTextStyle
richstyle.Bold = False
richStyle.Underline = False
richStyle.FontSize = 8
Call bodyitem.AppendStyle(richStyle)
Call bodyitem.AddNewline(2)
For zz = Lbound(hArray) To Ubound(hArray)
Call bodyitem.AppendText(hArray(zz).name)
Call bodyitem.AddTab(1)
Call bodyitem.AppendText(hArray(zz).fromval)
Call bodyitem.AddTab(1)
Call bodyitem.AppendText(hArray(zz).toval)
Call bodyitem.AddTab(1)
Call bodyitem.AppendText(Today)
Call bodyitem.AddTab(1)
Call bodyitem.AppendText(s.CommonUserName)
Call bodyitem.AddNewline(1)
Next
End If
Call histdoc.Save(True, False)
End If
The link you included also gives me the static fields check, like most of others solution I tried.
Anyhow, yours is very good. After all the try and seach, is the 1st time I see it gives the flexibility to read all the fields dynamically in order to keep track on the changes.
As per your highlight, I need to do some changes. Unfortunately, due to my lack of experience, I failed to get it right - it’s almost, always - three days I tried for at least 16 hours a day.
Dim doc As NotesDocument
Set doc = Source.Document
x = 0
Forall item In doc.Items
pos = Instr(item.name, "$")
If pos = 0 Then
Redim Preserve oArray(x)
oArray(x).name = item.name
oArray(x).value = doc.GetFirstItem(item.name).Text
x = x + 1
End If
End Forall