< Back

Document Subject: RichTextCommentsTracker
Hint Short Cut: Add this to your code & documentation to help you find this page.
http://#RTCommentsTrack or http://A555F9/nn.nsf/ByAlias/RTCommentsTrack

I have a nifty bit of code in a request database that kicks in when the request is changed after the first save. It allows additions to be made to a rich text field and it has name and date added so everyone concerned knows who added what. It also handles attachments and another version optionally emails the additions to anyone concerned.




How does it work?

 

Create the rich text field "rComments" in a section that is only editable to people with the [ChangeRT] role and when it is a new document.

Use this formula in the section computed formula:

@If(@IsDocBeingSaved;"[ChangeRT]";@IsNewDoc;"";"[ChangeRT]")

NB It is advisable to do this to allow tweaks to the text, even if you never give the role to anyone.

 

Put another rich text field "rAdditionalInfo" in a Comments subform that is invisible when the document is New.

I add a "LastaddedBy" field and a LastAddedWhen computed fields to show above this rich text field to show it is an additonal comments field.

Then when ever the form is edited, only the rAdditonalInfo Rich text field is available to be edited.

 

In the subform put in the QueryClose event, not QuerySave as it will not work, the following:

 
' This code:
' Adds the new rich text entered by the user from the rAdditionalInfo field
' in to the info field.
' Emails the members of the committee keyword list and also the developer if
' the developer has been specified

'Constants
Const TempDir$ = "C:\Temp\"  ' must end in \

If source.editmode Then
 Dim s As New notessession
 
 Dim doc As notesdocument
 Set doc = Source.document
 
 Dim Addinfo As notesrichtextitem
 Set Addinfo = doc.getfirstitem("rAdditionalInfo")
 
 If Addinfo Is Nothing Then
  Print "Cannot find rich text item rAdditonalInfo."
  End
 End If
 
 If Addinfo.text<> "" Or Isarray(Addinfo.embeddedobjects)  Then
 
  'set up string array for files to be deleted from the c drive.
  Redim filestodelete(0) As String
  filestodel=-1
 
  Dim r As notesrichtextitem
  Set r = doc.getfirstitem("rComments")
  If r Is Nothing Then
   Print "Cannot find rich text item rComments."
   End
  End If
 
  Call r.appendtext(" ")
  Call r.Addnewline(2)
  Call r.appendtext(" ")


  'Create rich text style
  Dim richStyle As NotesRichTextStyle
  Set richStyle = s.CreateRichTextStyle
  richStyle.NotesFont = FONT_HELV
  richStyle.NotesColor = COLOR_BLUE
  richStyle.FontSize = 9        

       
  Call r.AppendStyle(richStyle)
  Call r.AppendText(doc.LastAddedBy(0) & "   " & doc.LastAddedWhen(0))          
  Call r.Addnewline(1)
 
  'set to default text style
  Dim richStyleDef As NotesRichTextStyle
  Set richStyleDef = s.CreateRichTextStyle
  richStyleDef.NotesFont = FONT_HELV
  richStyleDef.NotesColor = COLOR_BLACK
  richStyleDef.FontSize = 9    
  Call r.AppendStyle(richStyleDef)
 
  'do the attachments first because merely doing an addrtiitem
  ' doesn't work with attachments
  If ( Addinfo.Type = RICHTEXT ) Then
   
   If Isarray ( Addinfo.EmbeddedObjects) Then
    Forall o In Addinfo.EmbeddedObjects
     If Not (o Is Nothing) Then
      If ( o.Type = EMBED_ATTACHMENT ) Then
       Call o.ExtractFile( TempDir$ & o.Source )                        
       Call r.embedobject( EMBED_ATTACHMENT, "" , TempDir$ & o.source )
       
       filestodel=filestodel+1
       Redim Preserve filestodelete(filestodel) As String
       filestodelete(filestodel) = o.source
       
       Call o.Remove    
       
      End If
     End If ' not nothing
    End Forall
    Call r.Addnewline(1)
   End If ' embedded objs not nothing
  End If
 
  Call r.Appendrtitem(Addinfo)
 
    'blank out fields
  doc.LastAddedBy=""
  doc.LastAddedWhen=""
 
  'save the document
  Call Addinfo.remove        
  Call doc.save(True,True)
 
  'Delete the files after saving to prevent null files
  Forall f In filestodelete
   If f<> "" Then
    Kill TempDir$ & f
   End If
  End Forall
 
 
 End If ' AddInfo isn't blank
End If ' in edit mode


You have to put the code in queryclose not querysave as the rich text field will not be saved properly.

The code detects that you might just add a file and no text and handles it.

Another version of this code emails the changes as well.

The files are deleted after saving to prevent empty files being saved.

This is a very efficient and productive method.

I keep it in a subform so I can drop it into other forms.

One problem I found was that if text is entered in a strange tab format the whole field becomes tabgled up in the format. This probably needs some sort of rich text ruler/paragraph/tab style adding to it, but it didn't happen enough to investigate this.