Solved

Document revision history in a Notes R5 field

Posted on 2008-10-13
6
1,218 Views
Last Modified: 2013-12-18
Hello,

I am trying to add a doc revision history at the bottom of a Notes form/doc. I just need date/time and user name of last 3 edits. I _really_ need to keep this as simple as possible. I've tried a few code snippets online but nothing has worked so far. Last code attempt is posted. Thanks in advance for any assistance.
This formula allows you to keep a revision history in a single computed field. Unlike most such revision trackers, it does not rely on the QuerySave event. The formula tests if the current user's name is in the most recent entry in the field. If so, only the date is updated so you don't get multiple entries for the same person if there is no intervening editor. The results display like this:
 

Joe Smith 10/29/2001 12:40:08 PM

George Bush 10/29/2001 12:40:46 PM

Rob Pinion 10/29/2001 12:50:15 PM

George Bush 10/29/2001 12:50:41 PM
 
 

Code
 
 

thisUser:=@Name([CN];@UserName);
 

REM "To use this function change the field name below from displayUpdater to your field name";

REM "The field should be Text, computed, allow multiple values, display separate entries with New Line"; 

thisfield:=displayUpdater;
 

REM "Assign all current lines in this field to a temporary variable";

existingLines:=thisfield;
 

REM "Each new line will have the user's name and the current date-time";

newLine:=thisUser+" "+@Text(@Now);
 

REM "Now compare to see if the current user is the most recent editor";

REM "Get the last entry since it contains the most recent editor";
 

REM "First get a count of the number of lines --- elements --- already there";

numLines:=@Elements(existingLines);
 

REM "If there's only one line assign it to lastEntry var, otherwise assign the last entry to lastEntry var";

lastEntry:=@If(numLines=1;existingLines;@Subset(existingLines;-1));
 

REM "Test whether the last line contains the name of the current user";

REM "Later we want to replace that line rather than adding a new line every time he saves the doc";

isSameUser:=@Contains(lastEntry;thisUser);
 

REM "Now get all lines but the last line";

allButLast:=@If(numLines=1;"";@Subset(existingLines;numLines-1));
 

REM "If the doc is being saved, then if this is same user return all but the last line followed by the new line";
 

REM "If this is not the same user, return everything preexisting plus a new line";
 

REM "If the doc is not being saved just show the contents of the field";
 

@If(@IsDocBeingSaved;@If(isSameUser;allButLast:newLine;thisfield:newLine);thisfield)

Open in new window

0
Comment
Question by:yim11
  • 3
  • 2
6 Comments
 
LVL 63

Expert Comment

by:SysExpert
Comment Utility
WHat is not working ?

Have you defined the field displayUpdater as required by this code ?

What is happening ?

Any errors ?

have you tried the debugger ?


 
I hope this helps !
0
 

Author Comment

by:yim11
Comment Utility
Thanks for the reply - I have defined the field displayUpdater to match my field name, when I say nothing is happening I mean that as literally as possible. Absolutely nothing is displayed - no field, no error, no data or information. I'm pretty sure that's due to the field being set to computed. Never run the debugger without an actual error so not sure how to do that. Sorry I don't have more info, let me know what else is needed.

Thanks,
-jim
0
 
LVL 63

Expert Comment

by:SysExpert
Comment Utility
have you tested this in a clean DB, in a simple form first, with nothing else but 1 other field ?

0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:yim11
Comment Utility
I have now. And was able to get it to work on a clean db and a couple basic fields (needed a text field to actually edit to make sure it was working) - and it does work in the sandbox. I copied the entire field/info over to the form I'm working with and it doesnt work. My first thought is that since this code was based on not having to use the Querysave event and my form DOES use a querysave event that may be whats messing things up, but not sure since I'm no Notes expert. I've attached the querysave code just in case it helps.

Thanks,
-jim

Sub Querysave(Source As Notesuidocument, Continue As Variant)

	If Source.Document.Size > 5000000 Then

		If Messagebox( "File is very large (" & Round( Source.Document.Size / 1000000, 0) _

		& "MB). Please reduce if possible before attach. Press CANCEL.   Press OK to attach anyway",  257, "Size check") _

		= 2 Then Continue = False

	End If

End Sub

Open in new window

0
 
LVL 3

Accepted Solution

by:
rd153 earned 500 total points
Comment Utility
You have a number of options available to you, however since you only want simple information, it would be just as easy to do this using the following collection of fields set out in a table:

txtCreatedBy - @Name (Computed when composed Text Field)

timCreatedDate - @Now (Computed when composed Date Field)

RN - @If(@IsDocBeingSaved;@If(RN="";1;(@Subset(RN;1) +1): @If(@Elements(RN)>4; @Subset(RN;4); RN));@IsNewDoc;"";RN) (Computed Numeric Field which displays revision number)

txtEditor - @If(@IsDocBeingSaved;@If(txtEditor = "";@Name([CN];@UserName);@Name([CN];@UserName) :@If(@Elements(txtEditor) >4 ; @Subset(txtEditor;4); txtEditor)); @IsNewDoc;"";txtEditor) (Computed Text Field which dispays editor name)

txtEditDate - @If(@IsDocBeingSaved; @If(txtEditDate = ""; @Now;@Now : @If(@Elements(txtEditDate) > 4 ; @Subset(txtEditDate; 4);txtEditDate)); @IsNewDoc;"";txtEditDate) (Computed Date Field which dispays modified date)

The attached gif provides some idea of what it would look like.  If you want to do the same thing in script, you can use a subform with something like this:

Field 'History'
Subform Declarations:
Dim session As NotesSession
Dim old List As String

PostOpen:
Sub Postopen(Source As Notesuidocument)
      Set session = New NotesSession
      Dim sRichText As String
      
      old("Subject") = Source.FieldGetText("Subject")
      old("Categories") = Source.FieldGetText("Categories")
      old("ReviewerList") = Source.FieldGetText("ReviewerList")
      old("ReviewType") = Source.FieldGetText("ReviewType")
      old("Body") = Source.FieldGetText("Body")
End Sub

QuerySave:
Sub Querysave(Source As Notesuidocument, Continue As Variant)
      On Error Goto E
      Source.Refresh
      On Error Goto 0
      
      initial = Source.IsNewDoc
      
      If initial Then m$ = session.CommonUserName & " - " & Cstr(Now()) & " - created document"
      
      Forall F In old
            v$ = Source.FieldGetText(Listtag(F))
            If Not initial And Not v$ = F Then
                  If m$ = "" Then
                        m$ = session.CommonUserName & " - " & Cstr(Now()) & " - modified "
                  Else
                        m$ = m$ & ", "
                  End If
                  If F = "" Then F = {""}
                  m$ = m$ &  Listtag(F) & Chr$(10) & " from " & Chr$(10) & F & Chr$(10) & " to " & Chr$(10) & v$
            End If
            F = v$
      End Forall
      
      If initial Then
            Source.FieldSetText "History", m$
      Elseif Not m$ = "" Then
            Source.FieldAppendText "History", Chr$(10) & m$
      End If
      
X: Exit Sub
      
E: Continue = False
      Resume X
End Sub
Edit-History.gif
0
 

Author Closing Comment

by:yim11
Comment Utility
Thanks!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now