Home > Domino Tips > Developer > LotusScript > How to create a comments field for Lotus Notes documents
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

LOTUSSCRIPT

How to create a comments field for Lotus Notes documents


Ray Green
11.21.2006
Rating: -2.53- (out of 5)


Lotus Notes and Domino tips, tutorials and how-to articles
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


VIEW MEMBER FEEDACK TO THIS TIP

To create a field for users to add notes or comments to a Lotus Notes document, you must first set up two fields.

The first, we'll call Cust_NotesTemp. It only has code in the Exiting Event. This is an editable field into which a user can enter notes or comments.

When they exit the field, the Exiting Event code trims the field of junk, stamps the new note or comment with the current date and time, adds a line feed. It then links the new comment together with the other comments already present in the Lotus Notes document, and saves it into the Cust_Notes field. When finished, it clears out the Cust_NotesTemp field.

One consideration is that the user may save the Lotus Notes document after entering comments into it, but before exiting the Cust_NotesTemp field. As such, the Exiting Event must be triggered when the document is saved by forcing the field exiting event, no matter where the cursor is. Move the cursor to some field at the beginning of the document that doesn't need any entering or exiting event code -- Call uidoc.GoToField("??? any field").

Now set up the second field and call it Cust_Notes. This field only has code in the Entering Event. This will store all notes or comments with dates/times, as well as the user's name that created each note. This is an editable, but restricted, field that only a user with manager access can edit. This prevents Lotus Notes users from changing their own comments or those of other users. Finally, add the following LotusScriptcode:

'Cust_NotesTemp Field - 
Exiting Event Sub Exiting(Source As Field)
Dim session As New NotesSession
Dim db As NotesDatabase
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set db = session.CurrentDatabase     
Set uidoc = workspace.CurrentDocument
'check that the user has added 
a new note and trim it of junk
custnotestemp = 
uidoc.FieldGetText("Cust_NotesTemp")
If custnotestemp = "" Then Exit Sub
Call TrimNotes(custnotestemp)              
'see TrimNotes subroutine below
'pick up any existing notes, and add a return before 
stamping a new date/time and user name 'then add the 
new notes after the last note
custnotes = uidoc.FieldGetText("Cust_Notes")
notestime = Format(Now,"DD/MM/YY HH:MM")
notesuser = session.CommonUserName
If custnotes = "" Then
custnotes = notestime & " : " 
& session.CommonUserName & " : " & custnotestemp
Else
If Instr ( 1 , custnotes , 
notestime & " : " & notesuser ) <> 0 Then          
custnotes = custnotes & "  "  & custnotestemp
Else
custnotes = custnotes & Chr(10) & notestime & " : " 
& session.CommonUserName & " : "   & custnotestemp
End If
End If
'save the new and old notes and 
clear out the temp notes field
Call uidoc.FieldSetText("Cust_Notes",custnotes)
Call uidoc.FieldSetText("Cust_NotesTemp","")
End Sub


'Cust_Notes Field - Entering Event
This field is used to store all notes made on a 
customer account, with the User Name, Date & Time
 the note was made.
The contents can't be changed by anyone other than 
a user defined with Manager Access.
Sub Entering(Source As Field)
Dim session As New NotesSession
Dim db As NotesDatabase
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim acl As NotesACL    
Dim entry As NotesACLEntry
Set db = session.CurrentDatabase     
Set uidoc = workspace.CurrentDocument     
Set acl = db.ACL
user = session.CommonUserName & "???"      
 'replace ??? with organization name
Set entry = acl.GetEntry( user )
If entry.IsRoleEnabled( "[MANAGER]" )Then
Exit Sub
Else
Call uidoc.GoToField("Cust_NotesTemp")
End If
End Sub



'Subroutine to Trim the Notes that are saved 
of all "junk" and unecessary 
characters Sub TrimNotes(fixthis)
t= fixthis
trimmed = ""     
found = "N"
'look for chr(13) or chr(10) and if found 
look for another and if found remove the second one
For x = 1 To Len(t)
'found the 1st CR or LF - accept it
If (Mid ( t , x , 1 ) = Chr(13) 
Or Mid ( t , x , 1 ) = Chr(10)) And found = "N" Then
found = "Y"
trimmed =  trimmed & Chr(10)
Goto getnext
End If
'found a 2nd or subsequent CR or LF - throw it away
If (Mid ( t , x , 1 ) = Chr(13) 
Or Mid ( t , x , 1 ) = Chr(10)) And found = "Y" Then
Goto getnext
End If
trimmed =  trimmed & Mid ( t , x , 1 )
found = "N"
getnext:
Next
t = trimmed     
'change double spaces to single space
a = "  "
b = " "
If (a<>b) Then 
i=Instr(t,a)
done=(i=0)
While Not done
t=Left(t,i-1)+b+Mid(t,i+Len(a))
n=i+1
i=Instr(n,t,a)
If i=0 Then i=Instr(t,a)
done=(i=0)
Wend
End If
'change // to /
a = "//"
b = "/"
If (a<>b) Then 
i=Instr(t,a)
done=(i=0)
While Not done
t=Left(t,i-1)+b+Mid(t,i+Len(a))
n=i+1
i=Instr(n,t,a)
If i=0 Then i=Instr(t,a)
done=(i=0)
Wend
End If     
'change double hyphens -- to single -
a = "--"
b = "-"
If (a<>b) Then 
i=Instr(t,a)
done=(i=0)
While Not done
t=Left(t,i-1)+b+Mid(t,i+Len(a))
n=i+1
i=Instr(n,t,a)
If i=0 Then i=Instr(t,a)
done=(i=0)
Wend
End If          
fixthis = Trim(t)          
End Sub

MEMBER FEEDBACK TO THIS TIP

I've found a much easier solution.

First, create two fields and call one Comments (make this an editable text field) and Comments_D (make this a computed text field). Next, use the following as the formula for the Comments_D field:

rtn := @If(@IsDocBeingSaved & 
Comments != "" ; @Text(@Date(@Today))
 + " - " + Comments + @NewLine 
+ Comments_D; Comments_D);
FIELD Comments := "";
rtn

Place the form in edit mode, enter some text, save the document and finally close the document. I must admit, this does not do the "clean up" that the author's LotusScript does, but that could be done with a couple of @ReplaceSubstring or @Replace commands added in.

Please allow me to add an appeal to everyone trying to do Lotus Notes/Domino development. Learn the @Functions! I see so many examples of programmers trying to do everything in LotusScript when a couple of simple @Functions can do the trick.
—Randy D.

******************************************

Randy D. is on the right track. I use the Formula language a lot and I have a form with three fields to update comments into one field and then clear the previous two so that they are blank for the next user.

To accomplish this, create two editable fields (UpdateSubject, which is optional, and UpdateDetail) and one computed field (UpdateLog). Then, create a button on the form and put this code behind it:

@IsDocBeingEdited = 0; 
@Command([EditDocument]; "1" );
updatetext := @NewLine+ "- 
Request updated on " + @Text(@Now) + 
" by " + @Name([CN]; @UserName)+ " 
- Subject: " +UpdateSubject+ " - Detail: " +UpdateDetail;
@SetField("UpdateLog"; UpdateLog + updatetext);
@Command([FileSave]);
@SetField("UpdateSubject"; null);
@SetField("UpdateDetail"; null);
@Command([FileSave])

This grabs the username, current date and time to add into the comment. The user types a subject in the UpdateSubject field (this is optional) and the comment in the UpdateDetail field. Then click the button and it immediately adds the comment to the log below. It saves the changes and then clears the Subject and Detail fields. It then saves the form again. You can use @Command([FileCloseWindow]) command at the end to close the document.
—Linda T.

Do you have comments on this tip? Let us know.

Related information from SearchDomino.com:

  • Tip: Prompting a Lotus Notes user for input using LotusScript
  • FAQ: LotusScript advice
  • Expert Advice: How to modify a Lotus Notes signature file using LotusScript
  • Learning Guide: LotusScript development

    This tip was submitted to the SearchDomino.com tip library by member Ray Green. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

    Rate this Tip
    To rate tips, you must be a member of SearchDomino.com.
    Register now to start rating these tips. Log in if you are already a member.


    Submit a Tip




    Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google



    RELATED CONTENT
    LotusScript
    LotusScript finds the first occurrence of a string from the right
    Clear Recent Contacts view and prevent repopulation in Lotus Notes 8.x
    Search Microsoft Active Directory with LotusScript
    Three steps to trap and handle save conflicts with LotusScript
    Troubleshoot agents by displaying LotusScript variables online
    LotusScript sorts lists alphabetically
    Run or restart Notes/Domino agents via text messages
    LotusScript code rebuilds corrupted busytime.nsf file
    Soft-code item names to facilitate LotusScript management
    LotusScript agent automates selective mail file replication

    LotusScript
    LotusScript finds the first occurrence of a string from the right
    Clear Recent Contacts view and prevent repopulation in Lotus Notes 8.x
    Search Microsoft Active Directory with LotusScript
    Three steps to trap and handle save conflicts with LotusScript
    Troubleshoot agents by displaying LotusScript variables online
    LotusScript sorts lists alphabetically
    LotusScript code rebuilds corrupted busytime.nsf file
    Soft-code item names to facilitate LotusScript management
    LotusScript agent automates selective mail file replication
    LotusScript filters and attaches files to a Notes form

    Lotus Notes Domino User Settings
    Secure Lotus Notes/Domino 8.x from mail to unknown recipients
    How to turn off the message recall feature in Lotus Notes 8
    Domino server setting and email policy tricks admins must know
    Top 10 Lotus Notes/Domino administration tips of 2008
    Synchronize LinkedIn contacts with Lotus Notes Domino
    Setting up local replication of a Lotus Notes database for offline employees
    Secure Microsoft Excel spreadsheets with LotusScript
    Programmatically create a shortcut for Lotus Notes
    The truth about AutoSave in Lotus Notes/Domino 7
    Restraining the monsters behind Lotus Notes' 'Full Access Administrator'

    RELATED RESOURCES
    2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
    Search Bitpipe.com for the latest white papers and business webcasts
    Whatis.com, the online computer dictionary

    DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



  • Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
    HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
    About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
    SEARCH 
    TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

    TechTarget Corporate Web Site  |  Media Kits  |  Site Map




    All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
      TechTarget - The IT Media ROI Experts