In many companies, the same email response must be sent many times when it has to do with the same product or technical support issue. With a few changes to the Notes mail template, Lotus Notes can store these responses and concatenate them into a standard response email. This function lets you add predetermined messages to your email message with a simple selection box and the click of a button. By adding a few new design elements to the mail template, you can choose from a self-made list of standard responses to add to a message.
There are two ways to implement this solution:
- Using @formulas and non-rich text documents (for release 3 and later)
A form button on the Memo form executes this @formula. This button adds chosen text to your email message. - Using LotusScript and rich text documents (for release 5 and later)
A shared action button in the mail views contains LotusScript that creates the email message and adds the chosen response documents. The LotusScript code uses dynamic arrays and the new Prompt method available in release 5 and later of Domino Designer.
This article explains both solutions and is intended for Notes application developers. Knowledge of the Notes formula language and/or LotusScript is helpful, but not required.
You can download sample Notes mail templates (release 5 and later) containing standard response documents from the Sandbox and replace the design of an existing mail database. See the SRTReadMeFirst.txt file with the sample template. This article describes the design work needed to modify the mail template to include this solution.
NOTE: Download or stream the Standard Response Text Flash demo from the Sandbox for an application presentation.
Developing the design elements
Here is an overview of the steps needed to implement our solution with all accompanying design elements added to the standard mail template:
- Design a new form on which the standard response documents are based.
- Create a view showing the standard response documents.
- Create an action button to run this application.
- For plain text documents, create an action button on the Memo form to add the text from the standard response documents to the current email message.
- For rich text documents, create a view action button that performs the lookup and concatenates the responses into a single message.
- Change all the mail views selection formulas to prevent display of the standard response documents.
- Create standard response documents in Lotus Notes.
- Check the final design.
Design a form with two fields. The first field is a plain text field for the subject. The subject field will include a short description of the standard response document. The second field is either a rich text field for the LotusScript solution or a plain text field for the @formula solution. This field contains the entire standard response. No other coding is required for the form.
Create a view to show the standard response documents with a column for the subjects. This is a new view for the mail database, and the view selection formula should be for the standard response documents only:
SELECT Form = "ResponseForm"
For the view name, you may want to use a hierarchy with Admin at the top, for instance, Admin\StandRespText. The purpose of this view in your mail file is to let you view, edit, and create the standard responses. For the agent to find the standard response documents, sort the title in ascending order as shown in the Admin\StandRespText view.
Figure 1. Standard response documents

For the rich text solution, the view action lets you reply to a selected email in your Inbox view. Open the ($Inbox) folder in Domino Designer and choose Create - Action - Action. In the programmer's pane, choose LotusScript, and then add the LotusScript button code in the side file, "Standard response document code example." To add this button to all the mail views in your mail database, create a shared action instead.
The view action button lets you select response documents to put together into a single email message, but there's much more to it than that. The following snippet of code counts the documents and stores the document subjects in a variable dimensioned array for the LotusScript equivalent of the @Prompt_OKCancelListMult.
i =1
Nod = 0 ' Number of documents in response view (initialize)
While (i < 3)
Set view=db.getview("Admin \ StandRespText")
Set curdoc1=view.getfirstdocument 'Line 50
Set curdoc2 = curdoc1
j=0
While Not (curdoc2 Is Nothing)
Set curdoc2 = view.GetNextDocument(curdoc1)
If ( i > 1) Then
If ( j = 0) Then
' ReDim only once when i =2 and j = 0
RDim=Nod - 1 ' Dimension starts at zero,
' so dimension number is one less than
' the number of documents
Redim StanResD(RDim) As Notesdocument
Redim itms(RDim) As String 'Line 60
End If
'---------------------------------------------------------------
' First loop of I does not get field from documents;
' counts the documents
If curdoc1.HasItem("Subject") Then
Set item = curdoc1.GetFirstItem("Subject")
itmv = curdoc1.GetItemValue("Subject")
itms(j) = Cstr(itmv(0))
j=j+1
End If
'--------------------------------------------------------------------
'Line 70
End If
Set curdoc1 = curdoc2
If ( i = 1) Then
Nod = Nod+1 ' Count the number of documents (nod)
' in this view for the first loop of I only
End If
Wend
i = i +1
Wend
|
This next code snippet displays the subject of each response document in a prompt box for the user to select any combination. The order shown in the display box is the order each rich text body field response is concatenated in the new email.
Set curuidoc = workspace.CurrentDocument userchuz = workspace.Prompt(PROMPT_OKCANCELLISTMULT,_ "Standard ResponseText List", "Please select the response text _ to use from the list","", itms) 'Line60 If (userchuz(0) <> "") Then 'Continue Goto Cont01 Else 'No Choice was made Exit Sub End If 'Line 90 Cont01: |
Now the code cycles through all the response documents to copy the chosen rich text fields. The responses are stored in a rich text item variable in memory.
K=0
upperBound = Ubound(userchuz)
While (K <= upperbound)
Set view=db.getview("Admin \ StandRespText")
Set curdoc1=view.getfirstdocument
Set curdoc2 = curdoc1 'Line100
j=0
While Not (curdoc2 Is Nothing)
Set curdoc2 = view.GetNextDocument(curdoc1)
If curdoc1.HasItem("Subject") Then
Set item = curdoc1.GetFirstItem("Subject")
itmv = curdoc1.GetItemValue("Subject")
itms(j) = Cstr(itmv(0))
' y is set to "0" if the following string does compare
y = Strcomp(itms(j),userchuz(k), 5)
If (y = 0) Then 'Line110
Goto Cont03 ' Choice is found; proceed to copy it
Else
' Choice is not found; keep looking
End If
j=j+1
End If
Set curdoc1 = curdoc2
Wend
' Choice not found
Exit Sub 'Line110
Cont03:
Set StanResD(k) = curdoc1 ' StanResD is now the standard_
' response document selected for copy
If (k < 1) Then
Set ritmv0 = StanResD(k).GetFirstItem("RBody")
Else
Set ritmv1 = StanResD(k).GetFirstItem("RBody")
Call ritmv0.AddNewLine( 1 )
Call ritmv0.AppendRTItem(ritmv1)
End If
k=k+1 'Line 120
Wend
|
Then it determines whether the memo is new, a reply, or a reply with history email and adds that information.
Dim repcol As NotesDocumentCollection
Dim repdoc As NotesDocument
Dim ritmv3 As NotesRichTextItem
Dim itmst As String
Set db = session.CurrentDatabase
Set repcol = db.UnprocessedDocuments
Set repdoc = repcol.GetFirstDocument
Set item = repdoc.GetFirstItem("Subject")
itmv = repdoc.GetItemValue("Subject")
itmst = Cstr(itmv(0))
message$ = " " & cr$ _
& " Current document in Inbox view = " + itmst + cr$ _
& "" + cr$_
& "New memo - Click Cancel" + cr$_
& "Reply To Cur Doc - Click Yes" + cr$_
& "Reply with History to Cur Doc - Click No"
boxType& = 19 ' MB_YESNOCANCEL + MB_ICONStop
answer% = Messagebox(message$, boxType&, _
"Inbox Highlighted Document!")
If(answer% = 2) Then
Call ritmv0.CopyItemToDocument(maildoc, "Body")
Goto ContResI ' Cancel - Continue with new e-Mail
Elseif(answer% = 6) Then
' Yes = Create a Reply Memo (No History)
Set item = repdoc.GetFirstItem("From")
Call item.CopyItemToDocument(maildoc, "SendTo")
Set item = repdoc.GetFirstItem("Subject")
itmv = repdoc.GetItemValue("Subject")
itmst = Cstr(itmv(0))
itmst = "RE:" + itmst
Set item = repdoc.ReplaceItemValue("Subject", itmst )
Call item.CopyItemToDocument(maildoc, + "Subject")
Call ritmv0.CopyItemToDocument(maildoc, "Body")
Elseif(answer% = 7) Then
' No Create a Reply Memo with History
Set item = repdoc.GetFirstItem("From")
Call item.CopyItemToDocument(maildoc, "SendTo")
Set item = repdoc.GetFirstItem("Subject")
itmv = repdoc.GetItemValue("Subject")
itmst = Cstr(itmv(0))
itmst = "RE:" + itmst
Set item = repdoc.ReplaceItemValue("Subject", itmst )
Call item.CopyItemToDocument(maildoc, "Subject")
Call ritmv0.AddNewLine( 2 )
Call ritmv0.AppendText _
( "Your E-mail: ")
Call ritmv0.CopyItemToDocument(maildoc, "Body")
Set ritmv3 = repdoc.GetFirstItem("Body")
Call ritmv3.CopyItemToDocument(maildoc, "Body")
Else
Exit Sub ' Cancel so quit out.
End If
ContResI:
|
Finally, it saves the chosen responses in the new email and opens the email in edit mode to add additional text or comments. The only caveat here is if the memo is cancelled at this time, a draft copy is still saved due to the background LotusScript classes used. Delete any unnecessary messages.
Call maildoc.save(False,False) ' Save Doc Set curuidoc = workspace.EditDocument( False,maildoc,False) ' The EditDocument method brings the back-end document into the front end. Goto TEnd |
Alternative @formula solution (plain text standard responses)
If you created a form with a plain text field instead of rich text field, use @formulas for the standard response documents. The simpler but very powerful @formula commands use the @DBColumn and @DBLookup to add standard response plain text to the email message. An @Prompt list box shows the response choices from the @DBLookup command and inserts this text in the email body field. To use the @formula solution, create an agent. In the "When should the agent run?" field, select "Manually from the agent list." In the "Which documents should it act on?" field, select "Run once (@commands may be used)." In the programmer's pane, choose Formula, and then add the following code:
ltroptions := @DbColumn("Notes" : "NoCache" ; "" : "" ; "ResponseView"; 1);
ltrdefault := @Subset(ltroptions; 1);
ltr := @Prompt([OKCANCELLIST]; "Standard ResponseText List";_
"Please select the response text to use from the list."; ltrdefault; ltroptions);
ltrtext := @DbLookup("Notes":"NoCache";"":"";"ResponseView"; ltr;"RBody");
@Command([EditGotoField]; "Body");
@Command([EditInsertText]; ltrtext);
@Command([EditInsertText]; @Char(0) + @Char(0));
@All
|
NOTE: You must sort the column with values used in the key for the @DBLookup formula. If this column is not sorted, a null value is returned, and the @formulas in the agent will not continue executing. In the following screen shot, the column in the view of non-rich text responses that contain the subjects, such as Opening Comment and Closing Comment, must be sorted (ascending or descending); otherwise, the line added to the email will be blank.
Figure 2. Result of plain text solution in a release 5 mail database

Create a form action button in the Memo form that calls this formula agent. In the programmer pane, select Simple Action(s), and then add the action to run the agent created above. In Lotus Notes 5, use the Add Action dialog box to select Run Agent in the Action field and to select your agent name.
Choose an appropriate icon for the action. In the Action Pane, choose Create - Action. Enter the name of the action, StandRespText, and select the position, for instance, show position 1 at the top of the list. Save the action by closing the pane.
The following sections apply to both the LotusScript rich text and the plain text @commands formula solutions.
Modify the All Documents and Draft views
Because these documents are not incoming or outgoing mail and do not have the same fields, you may want to keep them out of the normal mail views. In Domino Designer, open the ($All) view. In the Objects tab, select View Selection. The default view selection formula is:
SELECT @IsNotMember("A";ExcludeFromView)
Add the following line to the formula to prevent the standard response documents from appearing in the view:
& !@Contains(Form;"ResponseForm")
Save the view modifications.
You may also want to perform the same action on the Draft documents view. In Domino Designer, open the ($Drafts) view. In the Objects Tab, select View Selection to see the following formula:
SELECT PostedDate = "" & $MessageType = "" & @IsNotMember("D";ExcludeFromView) & ISMAILSTATIONERY != 1
Add the following line to the formula to prevent the standard response documents from appearing in the view:
& !@Contains(Form;"ResponseForm")
Create standard response text documents
In Lotus Notes, open the new view Admin \ Standard Response Text and create Standard Response Text documents from the Create menu. To make this more user friendly, you can add a view action button to create standard response documents. If your body field is rich text, you can add rich text elements, such as images, to the response. You must create at least one document or an error will occur (Error 184: Variant does not contain a container). If you use the sample database template, open the template in Lotus Notes and copy the sample standard response text documents. Check these documents and make edits or deletions.
As a final check to ensure that all modified design elements inherit the design from the new template database (SRTMDB.ntf), open the Design Properties box for each modified or new design element and select the "Prohibit design refresh or replace to modify" option. This allows the database to inherit the changes from the new template and lets other changes be inherited from the standard mail template. Otherwise, your changes can be placed in the mail template for all users.
Here is a list of design elements that changed:
- Form Document - Standard Response Text
- View - Admin \ StandRespText
- View - ($All)
- View - ($Drafts)
- Folder - ($Inbox)
- Memo form (non-rich text solution using formula commands only)
After changing the design properties, you can copy and paste the design elements from the sample database to your mail database or replace the design of the mail database with the corresponding version of the sample mail template from the Sandbox.
Using the new application (rich text solution)
The standard response documents appear in a dialog box when you click the view action button that you created previously. You can choose more than one response document from the dialog box, and Lotus Notes will create an email message containing all the responses you selected.
Figure 3. Choosing response documents from a list

NOTE: Documents begin with a number to create the order they are added to the email. For example, a new document with 40 (Closing Comment) at the beginning of the subject is inserted after a doc with a 20 (Face1-Face of Frustration) in the subject line.
The view action lets you choose a new memo, a reply message, or a reply with history message. Please read this message carefully. Domino Designer does not offer a way to make a pop-up box with multiple application designed buttons, so this method was chosen to make the response easier with just a click of a button. Instead of the pop-up box with Yes, No, and Cancel buttons, you can design a pop-up box with answers 1, 2, or 3 and error code for any other incorrectly typed data. This typing is more interaction than just clicking a button. In our example, the buttons mean the following:
- To create a new memo, click Cancel.
- To reply to current document, click Yes.
- To reply with history to the current document, click No.
Figure 4. Pop-up box

You can use a number of different email signatures by creating additional response text documents. You may want a signature for internal mail and a different one for external mail.
Here is an example of an email message. In figure 5, the body text, button, image, and signature are created in the message from individual response documents.
Figure 5. Email message with response documents

Remember that when you send a Notes rich text field over the Internet to another email system, the rich text field is converted to HTML, but still works fine in most newer email programs, especially Web mail clients.
As you can see, this is a very powerful add-on to any standard Notes mail template. You can add this custom feature in two minutes by choosing one of the appropriate release 5, release 6, or release 6.5 templates from the sample download file and replacing the design of your mail file. When Lotus Notes/Domino 7 is available, you can open the release 6.5 sample template in Domino Designer 7 and copy all the design elements discussed in this article to create a Notes 7 mail template for your users! Any number of response text documents can have their rich or plain text body field appended to an email message. The message can be further edited for custom answers before sending. Whatever you like, the choice is up to you!
- See the side file, "Standard response document code example," for the complete LotusScript action button code.
- Download the sample templates from the Sandbox.
- Download a Flash demo from the Sandbox, showing how to use this application.
- Download a trial version of Lotus Notes/Domino from the developerWorks: Lotus Downloads page.
- If you want to know more about LotusScript and the Notes formula language, see the Domino Designer help.
- Get involved in the developerWorks community by participating in
developerWorks blogs.
- Browse for books on these and other technical topics.
Donald Russell is an Advisory QA Engineer for Lotus Education and has been working in IBM's Lotus Software division since 1996. Prior to his current position, Donald was an advisory IS application developer and a senior Premium Notes Support Analyst. He holds a Bachelor of Science in Electrical Engineering and is a Certified Novell Administrator. Donald has written over 500 technical documents and white papers for the IBM DCF and Lotus Knowledge Base and has published technical articles for The View magazine. Outside of work, Donald was a Cub Scout Den leader and now an Assistant Scout Master for the Boy Scouts.




