jforget1
asked on
Edit History by Section?
Does anyone know if it is possible to have a separate edit history in multiple sections within the same document or of that only possible for the whole document.
Joe
Joe
It depends on how you are creating your edit history. The way I usually do it is to get the values of fields on opening the document, and during the save compare the current values with those stored before and log the changes that way. It would be no problem to log changes to some fields in a certain section and to log changes to other fields to a different one.
possible.... try this.
Remember fields' old value in the PostOpen and PostSave event
FIELD Field1Sec1Disp := Field1Sec1;
FIELD Field2Sec1Disp := Field2Sec1;
Section 1:
Field1Sec1 - editable
Field2Sec1 - editable
Field1Sec1Disp - computed for display with formula, Field1Sec1Disp
Field2Sec1Disp - computed for display with formula, Field2Sec1Disp
EditHistSec1 - computed allow multi-value, display separate values with new line with formula,
@Trim(EditHistSec1:@If(Fie ld1Sec1Dis p != Field1Sec1;@Text(@Now) +
" - Field 1 was changed.";""):@If(Field2Se c1Disp != Field2Sec1;@Text(@Now) +
" - Field 2 was changed.";""))
do the same for other section.
hope it helps.
Remember fields' old value in the PostOpen and PostSave event
FIELD Field1Sec1Disp := Field1Sec1;
FIELD Field2Sec1Disp := Field2Sec1;
Section 1:
Field1Sec1 - editable
Field2Sec1 - editable
Field1Sec1Disp - computed for display with formula, Field1Sec1Disp
Field2Sec1Disp - computed for display with formula, Field2Sec1Disp
EditHistSec1 - computed allow multi-value, display separate values with new line with formula,
@Trim(EditHistSec1:@If(Fie
" - Field 1 was changed.";""):@If(Field2Se
" - Field 2 was changed.";""))
do the same for other section.
hope it helps.
Just an embellishment and a correction from cezar's suggestion. As mentioned before, you would have to "preserve" the document's old values collectins the previous value fields when the document is saved.
If you want to keep track of all edit histories, then you would need to track the old edit history in order to append the new history to it, and if you expect the length to exceed a notes limitation for text fields, you might have to track the size of the edit history and truncate it as needed.
If there is an edit history for one section of the form: edithistory1
and this should track: field_1, field_2, field_3
And there is an edit history for a second section of the form: edithistory2
and this should track: field_4, field_5, field_6
Then when the form opens into edit mode: PostOpen AND PostModeChange -if the form is first opened in read mode and then switched to edit mode) AND PostSave, as cezar indicated you need to copy the current values into backup fields.
I assume you want the edit history to look something like this:
01/21/2006 8:00 AM - John Doe made the following changes:
Field_1 changed from XXX to XYZ
01/20/2006 9:00 AM - Mary Smith made the following changes:
Field_2 changed from 99.00 to 105.00
01/19/2006 10:00 AM - Mary Smith - no changes to this section
01/19/2005 8:00 AM - John Doe: document created.
If you want the edit history to track with most recent first, and then also keep a record of changes then you would need a bit more code in your computed field.
Here's what I did:
Copy the following into the POSTOPEN and POSTMODECHANGE:
-------------------------- ---------- ---------- ---------- ---------- ----------
Sub Postopen(Source As Notesuidocument)
%REM
This assumes you have two edit history fields
Replace your field names with the ones below, and then make sure you replace in all sections and under edithistory
%END REM
Dim Session As New NotesSession
Dim db As NotesDatabase
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set db = session.currentdatabase
Dim doc As NotesDocument
Set uidoc = ws.currentdocument
Set doc = ws.currentdocument.documen t
Dim strHistory As String
Dim k As Integer
Const vbNullStr = ""
strHistory= Format(Now(),"mm/dd/yyyy hh:mm:ss AM/PM") + " - " + session.commonusername + ": "
If source.EditMode Then
If source.isNewDoc Then
REM is a new doc so set the edit history
For k = 1 To 2
doc.ReplaceItemValue "EditHistory_" + Cstr(k), strHistory + "Document Created"
Next
With doc
.field_1OLD=vbNullStr
.field_2OLD=vbNullStr
.field_3OLD=vbNullStr
.field_4OLD=vbNullStr
.field_5OLD=vbNullStr
.field_6OLD=vbNullStr
End With
Else
REM is not a new doc so set the OLD values.
With doc
.field_1OLD=.field_1
.field_2OLD=.field_2
.field_3OLD=.field_3
.field_4OLD=.field_4
.field_5OLD=.field_5
.field_6OLD=.field_5
End With
End If
End If
Set doc = Nothing
End Sub
-------------------------- ---------- ---------- ---------- ---------- -----
Copy the following into the POSTSAVE:
Sub Postsave(Source As Notesuidocument)
Dim Session As New NotesSession
Dim db As NotesDatabase
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set db = session.currentdatabase
Dim doc As NotesDocument
Set uidoc = ws.currentdocument
Set doc = ws.currentdocument.documen t
If source.EditMode Then
REM is not a new doc so set the OLD values.
With doc
.field_1OLD=.field_1
.field_2OLD=.field_2
.field_3OLD=.field_3
.field_4OLD=.field_4
.field_5OLD=.field_5
.field_6OLD=.field_6
End With
End If
Set doc = Nothing
End Sub
-------------------------- ---------- --
EditHistory1: computed, multivalue, be sure to go to the MultiValue Field Options (the HAT tab) and set both to just "New Line"
EditHistory2: is the same as EditHistory1, just with the field names changed. I included it here so you can see the difference.
Now I did this with a fldNEW and fldOLD rather than looping through fld_1,fld_2, etc., because I didn't know how your field names were set up. You add sections: i.e. v1, v2, v3, v4, and so on by just copying this part over and over, incrementing v, and changing field_1, field_1OLD to the correct field names:
@Set("fldNEW";field_1);
@Set("fldOLD";field_1OLD);
v1:=@If(fldOLD!=fldNEW & fldOld !="" ;
"Field1 changed from " + q + @If(fldOLD!="";@Text(fldOL D);"Empty" ) + q + " to "
+ q + @If(fldNEW !="";@Text(fldNEW);"Empty" ) + q;"");
Then you would have to add the other v's to:
Changed:=@If(@Trim(v1:v2:v 3)="";"";t b + @Trim(v1:v2:v3));
-------------------------- -EditHisto ry1 START
strHistoryNew:=@Text(@Now) + " - " + @Name([CN];@UserName) + ":Document Created ";
strHistoryChanged:=@Text(@ Now) + " - " + @Name([CN];@UserName) + " Made the following Changes:";
strNoChanges:=@Text(@Now) + " - " + @Name([CN];@UserName) + " : No changes made to this section";
OldHistory:=EditHistory1;
Field fldNEW:="":
Field fldOLD:="";
q:=@Char(34);
tb:=" -";
@Set("fldNEW";field_1);
@Set("fldOLD";field_1OLD);
v1:=@If(fldOLD!=fldNEW & fldOld !="" ;
"Field1 changed from " + q + @If(fldOLD!="";@Text(fldOL D);"Empty" ) + q + " to "
+ q + @If(fldNEW !="";@Text(fldNEW);"Empty" ) + q;"");
@Set("fldNEW";field_2);
@Set("fldOLD";field_2OLD);
v2:=@If(fldOLD!=fldNEW & fldOld !="" ;
"Field2 changed from " + q + @If(fldOLD!="";@Text(fldOL D);"Empty" ) + q + " to "
+ q + @If(fldNEW !="";@Text(fldNEW);"Empty" ) + q;"");
@Set("fldNEW";field_3);
@Set("fldOLD";field_3OLD);
v3:=@If(fldOLD!=fldNEW & fldOld !="" ;
"Field3 changed from " + q + @If(fldOLD!="";@Text(fldOL D);"Empty" ) + q + " to "
+ q + @If(fldNEW !="";@Text(fldNEW);"Empty" ) + q;"");
Changed:=@If(@Trim(v1:v2:v 3)="";"";t b + @Trim(v1:v2:v3));
@If(@IsNewDoc;strHistoryNe w;
@if(Changed="";strNochange s:OldHisto ry;
StrHistoryChanged:Changed: OldHistory ))
-------------------------- ---------- ---END EditHistory1
-------------------------- -StartEdit History2 (same, just field name changes)
strHistoryNew:=@Text(@Now) + " - " + @Name([CN];@UserName) + ":Document Created ";
strHistoryChanged:=@Text(@ Now) + " - " + @Name([CN];@UserName) + ": Made the following Changes";
strNoChanges:=@Text(@Now) + " - " + @Name([CN];@UserName) + " : No changes made to this section";
OldHistory:=EditHistory2;
Field fldNew:="":
Field fldOLD:="";
q:=@Char(34);
tb:=" -";
@Set("fldNEW";field_4);
@Set("fldOLD";field_4OLD);
v4:=@If(fldOLD!=fldNEW & fldOLD !="" ;
"Field1 changed from " + q + @If(fldOLD!="";@Text(fldOL D);"Empty" ) + q + " to "
+ q + @If(fldNEW !="";@Text(fldNEW);"Empty" ) + q;"");
@Set("fldNEW";field_5);
@Set("fldOLD";field_5OLD);
v5:=@If(fldOLD!=fldNEW & fldOLD !="" ;
"Field1 changed from " + q + @If(fldOLD!="";@Text(fldOL D);"Empty" ) + q + " to "
+ q + @If(fldNEW !="";@Text(fldNEW);"Empty" ) + q;"");
@Set("fldNEW";field_6);
@Set("fldOLD";field_6OLD);
v6:=@If(fldOLD!=fldNEW & fldOLD !="" ;
"Field1 changed from " + q + @If(fldOLD!="";@Text(fldOL D);"Empty" ) + q + " to "
+ q + @If(fldNEW !="";@Text(fldNEW);"Empty" ) + q;"");
Changed:=@If(@Trim(v4:v5:v 6)="";"";t b + @Trim(v4:v5:v6));
@If(@IsNewDoc;strHistoryNe w;
@if(Changed="";strNochange s:OldHisto ry;
StrHistoryChanged:Changed: OldHistory ))
-------------------------- ----End EditHistory2
good luck!
m
If you want to keep track of all edit histories, then you would need to track the old edit history in order to append the new history to it, and if you expect the length to exceed a notes limitation for text fields, you might have to track the size of the edit history and truncate it as needed.
If there is an edit history for one section of the form: edithistory1
and this should track: field_1, field_2, field_3
And there is an edit history for a second section of the form: edithistory2
and this should track: field_4, field_5, field_6
Then when the form opens into edit mode: PostOpen AND PostModeChange -if the form is first opened in read mode and then switched to edit mode) AND PostSave, as cezar indicated you need to copy the current values into backup fields.
I assume you want the edit history to look something like this:
01/21/2006 8:00 AM - John Doe made the following changes:
Field_1 changed from XXX to XYZ
01/20/2006 9:00 AM - Mary Smith made the following changes:
Field_2 changed from 99.00 to 105.00
01/19/2006 10:00 AM - Mary Smith - no changes to this section
01/19/2005 8:00 AM - John Doe: document created.
If you want the edit history to track with most recent first, and then also keep a record of changes then you would need a bit more code in your computed field.
Here's what I did:
Copy the following into the POSTOPEN and POSTMODECHANGE:
--------------------------
Sub Postopen(Source As Notesuidocument)
%REM
This assumes you have two edit history fields
Replace your field names with the ones below, and then make sure you replace in all sections and under edithistory
%END REM
Dim Session As New NotesSession
Dim db As NotesDatabase
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set db = session.currentdatabase
Dim doc As NotesDocument
Set uidoc = ws.currentdocument
Set doc = ws.currentdocument.documen
Dim strHistory As String
Dim k As Integer
Const vbNullStr = ""
strHistory= Format(Now(),"mm/dd/yyyy hh:mm:ss AM/PM") + " - " + session.commonusername + ": "
If source.EditMode Then
If source.isNewDoc Then
REM is a new doc so set the edit history
For k = 1 To 2
doc.ReplaceItemValue "EditHistory_" + Cstr(k), strHistory + "Document Created"
Next
With doc
.field_1OLD=vbNullStr
.field_2OLD=vbNullStr
.field_3OLD=vbNullStr
.field_4OLD=vbNullStr
.field_5OLD=vbNullStr
.field_6OLD=vbNullStr
End With
Else
REM is not a new doc so set the OLD values.
With doc
.field_1OLD=.field_1
.field_2OLD=.field_2
.field_3OLD=.field_3
.field_4OLD=.field_4
.field_5OLD=.field_5
.field_6OLD=.field_5
End With
End If
End If
Set doc = Nothing
End Sub
--------------------------
Copy the following into the POSTSAVE:
Sub Postsave(Source As Notesuidocument)
Dim Session As New NotesSession
Dim db As NotesDatabase
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set db = session.currentdatabase
Dim doc As NotesDocument
Set uidoc = ws.currentdocument
Set doc = ws.currentdocument.documen
If source.EditMode Then
REM is not a new doc so set the OLD values.
With doc
.field_1OLD=.field_1
.field_2OLD=.field_2
.field_3OLD=.field_3
.field_4OLD=.field_4
.field_5OLD=.field_5
.field_6OLD=.field_6
End With
End If
Set doc = Nothing
End Sub
--------------------------
EditHistory1: computed, multivalue, be sure to go to the MultiValue Field Options (the HAT tab) and set both to just "New Line"
EditHistory2: is the same as EditHistory1, just with the field names changed. I included it here so you can see the difference.
Now I did this with a fldNEW and fldOLD rather than looping through fld_1,fld_2, etc., because I didn't know how your field names were set up. You add sections: i.e. v1, v2, v3, v4, and so on by just copying this part over and over, incrementing v, and changing field_1, field_1OLD to the correct field names:
@Set("fldNEW";field_1);
@Set("fldOLD";field_1OLD);
v1:=@If(fldOLD!=fldNEW & fldOld !="" ;
"Field1 changed from " + q + @If(fldOLD!="";@Text(fldOL
+ q + @If(fldNEW !="";@Text(fldNEW);"Empty"
Then you would have to add the other v's to:
Changed:=@If(@Trim(v1:v2:v
--------------------------
strHistoryNew:=@Text(@Now)
strHistoryChanged:=@Text(@
strNoChanges:=@Text(@Now) + " - " + @Name([CN];@UserName) + " : No changes made to this section";
OldHistory:=EditHistory1;
Field fldNEW:="":
Field fldOLD:="";
q:=@Char(34);
tb:=" -";
@Set("fldNEW";field_1);
@Set("fldOLD";field_1OLD);
v1:=@If(fldOLD!=fldNEW & fldOld !="" ;
"Field1 changed from " + q + @If(fldOLD!="";@Text(fldOL
+ q + @If(fldNEW !="";@Text(fldNEW);"Empty"
@Set("fldNEW";field_2);
@Set("fldOLD";field_2OLD);
v2:=@If(fldOLD!=fldNEW & fldOld !="" ;
"Field2 changed from " + q + @If(fldOLD!="";@Text(fldOL
+ q + @If(fldNEW !="";@Text(fldNEW);"Empty"
@Set("fldNEW";field_3);
@Set("fldOLD";field_3OLD);
v3:=@If(fldOLD!=fldNEW & fldOld !="" ;
"Field3 changed from " + q + @If(fldOLD!="";@Text(fldOL
+ q + @If(fldNEW !="";@Text(fldNEW);"Empty"
Changed:=@If(@Trim(v1:v2:v
@If(@IsNewDoc;strHistoryNe
@if(Changed="";strNochange
StrHistoryChanged:Changed:
--------------------------
--------------------------
strHistoryNew:=@Text(@Now)
strHistoryChanged:=@Text(@
strNoChanges:=@Text(@Now) + " - " + @Name([CN];@UserName) + " : No changes made to this section";
OldHistory:=EditHistory2;
Field fldNew:="":
Field fldOLD:="";
q:=@Char(34);
tb:=" -";
@Set("fldNEW";field_4);
@Set("fldOLD";field_4OLD);
v4:=@If(fldOLD!=fldNEW & fldOLD !="" ;
"Field1 changed from " + q + @If(fldOLD!="";@Text(fldOL
+ q + @If(fldNEW !="";@Text(fldNEW);"Empty"
@Set("fldNEW";field_5);
@Set("fldOLD";field_5OLD);
v5:=@If(fldOLD!=fldNEW & fldOLD !="" ;
"Field1 changed from " + q + @If(fldOLD!="";@Text(fldOL
+ q + @If(fldNEW !="";@Text(fldNEW);"Empty"
@Set("fldNEW";field_6);
@Set("fldOLD";field_6OLD);
v6:=@If(fldOLD!=fldNEW & fldOLD !="" ;
"Field1 changed from " + q + @If(fldOLD!="";@Text(fldOL
+ q + @If(fldNEW !="";@Text(fldNEW);"Empty"
Changed:=@If(@Trim(v4:v5:v
@If(@IsNewDoc;strHistoryNe
@if(Changed="";strNochange
StrHistoryChanged:Changed:
--------------------------
good luck!
m
ASKER
Wow marilyn this is impressive, if I just wanted to have it capture the date an edit happens and who did it, would that change this dramatically. I don't need to know what was changed, just a basic log for each section.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
oops, typo:
this is wrong>> .field_6OLD=.field_5
this is right>> .field_6OLD=.field_6
You get the idea, if your field name is: UserName, address, phone and UserName1, Address1, Phone1 then the script would look like this:
.UserNameOLD = .UserName
.AddressOLD = .Address
.phoneOLD = .phone
.UserName1OLD = .UserName1
.Address1OLD = .Address1
.phone1OLD = .phone1
this is wrong>> .field_6OLD=.field_5
this is right>> .field_6OLD=.field_6
You get the idea, if your field name is: UserName, address, phone and UserName1, Address1, Phone1 then the script would look like this:
.UserNameOLD = .UserName
.AddressOLD = .Address
.phoneOLD = .phone
.UserName1OLD = .UserName1
.Address1OLD = .Address1
.phone1OLD = .phone1
simple solution for a simple problem. a few lines of formula will do all.
ASKER
Marilynq I appreciate the detailed information, I will be trying to work this into my db soon so hopefully I can take this from here, but may have some addiotnal questions.
Sure no problem.
That may solve your problem easily.
I hope this helps !