Link to home
Start Free TrialLog in
Avatar of jforget1
jforget1

asked on

Edit history by section revisited

Recently MarilynQ was nice enough to help me with some code and I am hoping that now that I have some more details she will be able to give me a more exact code for the project I am working on. The link below is the one for the original explanation of the code.

https://www.experts-exchange.com/questions/21704573/Edit-History-by-Section.html

The way it finally panned out is that for each section I have 3 fields laid out as shown below. The completed1 is a checkbox selected when a task is complete and the user enters the date completed. The comments below those field are for all other notes and attachments needed for the section. This syntax is repeated for each section ticking up the digit for each section completed2, completed3...etc.

I would like to make a note in the edit history like the sample below, I just want to know if someone has edited any of the 3 fields within that section, I don't need to know what was editied exactly. If I can't do it with one edit based on all 3 fields, I could do it off the comments field as the user will always make some final comments when they mark the section completed.

Fields in section:
[completed1] on [complete_date1]
Comments: [comments1]

Edit History Sample
Last Modified by    On
user1                   2/1/2006 at 12:00
Avatar of marilyng
marilyng

Hi jforget1,

Sure, I will see what I can noodle out from the solution posted for you.   Just so I understand, for section 1, you have
completed1 and complete1date?

And similar field names for the remaining two sections?


Avatar of jforget1

ASKER

There is also a comments field, which if it is simpler could be the only one to tie into, I will just instruct them to always make a comment if changing anything so it ends up in the edit history. So comments1, comments2...3,4 is the one it can be tied to. And then I have to duplicate it to about 30 sections but once I get one the rest are gravy.

Thanks again
Joe
ASKER CERTIFIED SOLUTION
Avatar of marilyng
marilyng

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK I have renamed all the field to be consecutive, placed the post open and post save code. I then place the code for the computed EditHistory field in and it is tracking changes but initially there are 2 things that are out of whack.

First, is how do I change the code so it puts a return after each entry, they are just going in line now and it will get messy fast.

Second, right now it seems that any time I change any of the fields all the edit histories update, not just within its own section.  

I am including the first two sections, should this line @Set("fldNEW";completed1); be the same as the field in the section?

Section 1 code

strHistoryNew:=@Text(@Now) + " - " + @Name([CN];@UserName) + ":Document Created ";
strHistoryChanged:="Last modified by: " + @Name([CN];@UserName) + " on " + @Text(@Now);
strNoChanges:=@Text(@Now) + " - " + @Name([CN];@UserName) + " : No changes made to this section";

FIELD fldNew:="":
FIELD fldOLD:="";

OldHistory:=EditHistory1;
@Set("fldNEW";completed1);
@Set("fldOLD";completed1OLD);
V1:=@If(fldOLD!=fldNEW & fldOLD !="" ;"Changed";"");

@Set("fldNEW";complete_date1);
@Set("fldOLD";complete_date1OLD);
V2:=@If(fldOLD!=fldNEW & fldOLD !="" ;"Changed";"");

@Set("fldNEW";comments1);
@Set("fldOLD";comments1OLD);
V3:=@If(fldOLD!=fldNEW & fldOLD !="" ;"Changed";"");

Changed:=@If(@Trim(V1:V2:V3)="";"";"Changed");

@If(@IsNewDoc;strHistoryNew;
      @If(Changed="";OldHistory;StrHistoryChanged:OldHistory))

Section 2 code

strHistoryNew:=@Text(@Now) + " - " + @Name([CN];@UserName) + ":Document Created ";
strHistoryChanged:="Last modified by: " + @Name([CN];@UserName) + " on " + @Text(@Now);
strNoChanges:=@Text(@Now) + " - " + @Name([CN];@UserName) + " : No changes made to this section";

FIELD fldNew:="":
FIELD fldOLD:="";

OldHistory:=EditHistory2;
@Set("fldNEW";completed2);
@Set("fldOLD";completed2OLD);
V1:=@If(fldOLD!=fldNEW & fldOLD !="" ;"Changed";"");

@Set("fldNEW";complete_date2);
@Set("fldOLD";complete_date2OLD);
V2:=@If(fldOLD!=fldNEW & fldOLD !="" ;"Changed";"");

@Set("fldNEW";comments2);
@Set("fldOLD";comments2OLD);
V3:=@If(fldOLD!=fldNEW & fldOLD !="" ;"Changed";"");

Changed:=@If(@Trim(V1:V2:V3)="";"";"Changed");

@If(@IsNewDoc;strHistoryNew;
      @If(Changed="";OldHistory;StrHistoryChanged:OldHistory))
OK I have done some more testing and it seems that as I go down the page and make edits to other sections it keeps adding edit histories to the sections above that current section. If I keep clicking in any sections they all keep adding edit histories.
jforget1,
Sub Postopen(Source As Notesuidocument) << Also put this code in the POSTMODECHANGE event


Const NUM_SECTIONS = 2                      '<<<<IMPORTANT! CHANGE THIS TO THE TOTAL NUMBER OF SECTIONS if you have 15 sections then
                                                                change this to:

Const NUM_SECTIONS = 15

(***Else it will just replace sections 1 and section 2 :)

EditHistory1 formula should equal EditHistory1
EditHistory2 formula should equal EditHistory2
     (sometimes when you cut and paste, you forget to change the value.  In R6 you can use @ThisValue, I think

>>Your question, should:
   OldHistory:=EditHistory1;
   @Set("fldNEW";completed1);
   @Set("fldOLD";completed1OLD);
be the same for the section, yes.   So the above formula would appear in the EditHistory1 section. (Through the entire code)

In editHistory15 change all the "1's" to 15:

    OldHistory:=EditHistory15;
   @Set("fldNEW";completed15);
   @Set("fldOLD";completed15OLD);


------------------------
To change the modified so it appears last in the EditHistory:

Change this:
@If(@IsNewDoc;strHistoryNew;
      @If(Changed="";OldHistory;StrHistoryChanged:OldHistory))

To This:
@If(@IsNewDoc;strHistoryNew;
      @If(Changed="";OldHistory;OldHistory:StrHistoryChanged))

I have checked and all the field naming appears to be correct. What is weird is as I tab through any section in the document it keeps adding an edit item each time for the history, even sections I have not duplicated the code to. I only have it in 4 sections and have that number in the various post sections, I also added the code to the postmodechange and it is still creating the large number of edits.

For the last item, I am not as concerned with the order of the edits but there is a line break after each. they just look like a big run on sentence right now.

I am putting in every point I have because I know this is a tricky one.
Turn off automatic updates on both the check box and the form.

THe edithistory field should be a multi-value field, with the line set to create a new break after a line break, and include a line break after each line break.  Also, put in an EditHistory1_OLD, EditHistory2_OLD, etc.  These should be computed, multivalued, and equal to themselves.

If you open the field properties, and click on the HAT tab, the Multi-Value Options both of these should be set to New Line in the regular and OLD fields.

You're missing something, because when I try this, and tab to the next field, nothing changes.  So you must have validation stuff, or transition formulas that are firing.  My email is in my profile, if you send me your email, I will send you a dtabase example.

It's really not tricky, you just have to have an understanding of what's happening when.  You shouldn't be writing into every field when you're in one section unless your formulas are wrong.. that is the EditHistory2 has the edithistory1 formulas.

If the edit history is firing when you tab, then your form is refreshing or saving and the edithistory is recalculating.
I will try the suggestions above, and this may not be tricky to you, but I am still a rookie in this and appreciate all the help.
Marilyn

That did it, I think the refresh on the form was causing all the problem and the multi value adjustment is exactly what I am looking for, thanks for all the help.

Joe
jforget1 - good!  Cool that it worked.