We help IT Professionals succeed at work.

Create and populate stationery in lotusscript

KDrago asked
Medium Priority
Last Modified: 2013-12-18
Hello -

Hoping I can get a good overview of how to go about doing the following.  I need to create a function that will allow users to create and save mail templates (stationery) in a database.  The users then need to be able to open mail received in this database, click a "template" button that will create a reply (with history) formatted with the template they selected.  I'd like to grab information from the email to use in populating the greeting (ie Dear <fromName>).

 - So far I have created a "template" form that has the following fields:

- I have also created a button on the inbound email form that displays a picklist of the templates that can be used.  

After this I am kind of stuck as to how to create the reply memo using the body of the saved template.  Also, don't know how to get the history appended to this template.

I tried looking at the mail template for guidance, but the notes templates are a little too overdone for what I need and therefore more confusing than just doing it from scratch.  I would like a solution using lotusscript.

Watch Question

Basically, your templates are responses, and in the FORM properties for these templates, VERY EASY,

Go to the SECOND tab
Check:  Formula inherits values from selected document
Check: Inherit entire document into Rich Text Field, then specify "Body" as your RT Field, and as "Collapsible Text"

check on close present mail send dialog.

No need for lotus script, unless you want to do other fancy things :)


Hi marilyng -

Thanks for your response.  I have already developed most of this using lotusscript.  I am building the body field of a memo using field append text.  I am now trying to get the history appended to the end of the body field.  I have a handle on the open email.  I copy the entire uidoc using uidoc.select all and uidoc.copy.  Now I want to position and paste it to the end of the body field I have been formatting.  Is there anyway to do this?

Thanks again for your time.



oh I should add I have uidoc.paste in my code after all of my body field text is entered.  It is placing the paste in a completely different field altogether.  I just don't know how to position the cursor to where I need it to paste
Hmmm...let's see, usually when I do this, I build the entire document backend, and then open it front end.  (Which emulates how Notes does this when you press the "reply" button)

Anything is possible - just depends how elegant you want to be, and how much code you want to write :)

So, let's see.  

You have an email that appears in your database, and when opened, you have an action button that prompts the user to select a template to use.
Based on the template selected, you copy the currently opened email, open a new document, and paste the template body into the body field followed by the entire open document as history...

So, because the ability to navigate isn't available in ui, you would have to open the template, copy it, switch to the reply, paste that, add a few lines, switch back to the original email, copy that, then switch back to the reply and append that.  Not very elegant ;)


I hope your templates are separate documents.. if not, make them a separate form.. two fields:  Title (so you can recognize them) and rich text body, that contains the "body" of your pre-determined message.

Create a "Templates" view with one column - Title.

This script supposes that your "Reply" is a form with the name "Reply" and has the standard Body field, it also assumes that the opened email has the following fields: from, subject, body.

Put an action button on the email document called "Reply" and paste this into the script formula:

Sub Click(Source As Button)
    Dim Session As New NotesSession
    Dim db As NotesDatabase
    Dim ws As New NotesUIWorkspace
    Dim uidoc As NotesUIDocument
    Set db = session.currentdatabase
    Dim doc As NotesDocument
    Dim reply As NotesDocument
    Dim template As NotesDocument
    Set uidoc = ws.currentdocument
    Set doc = ws.currentdocument.document
    Dim richTitle As NotesRichTextStyle
    Dim richNormal As NotesRichTextStyle
    Set richTitle = session.CreateRichTextStyle    
    With richTitle
        .NotesFont = Font_helv
        .FontSize = 10
        .NotesColor = Color_blue
        .Bold = True
    End With    
    'Select template to use
    Dim coll As NotesDocumentCollection
    'Asks the user to select a template from the TEMPLATES view - some title in the first column to select
    Set coll = ws.PickListCollection( PICKLIST_CUSTOM,False,db.server,db.FileName,"Templates","Select a Template","Select a template to use")
    If coll.count<1 Then
        Msgbox "Sorry, you must select a template to use",,"No template selected"
        Exit Sub
    End If
    Set template = coll.GetFirstDocument
    If template Is Nothing Then
        Msgbox "Oops, the template you selected doesn't seem to be available",,"Unable to Continue"
        Exit Sub
    End If
    'This gets the template BODY item  and copies it
    Dim templateItem As NotesRichTextItem
    Set templateItem = template.GetFirstItem("Body")    
    Set reply =db.CreateDocument
    With reply
        .form = "Reply"
        .from = session.UserName
        .principal = session.UserName
        .sendTo = doc.from
        .subject = "Re: " + doc.subject(0)
        .makeresponse doc        
    End With
    Dim rtItem As New NotesRichTextItem(Reply,"Body")
    'Going to dump the current document into tmpbody so I can append it into a section
    Dim tmpItem As New NotesRichTextItem(Reply,"tmpBody")
    Call doc.RenderToRTItem (tmpItem)
    With rtitem
        .AddNewline 1,False
        If Not templateItem Is Nothing Then
            If templateitem.type = RICHTEXT Then
                .Appendrtitem templateItem
                Forall t In templateitem.Values
                    .appendText t                    
                End Forall                
            End If
        End If
        .AddNewline 2,False                
    End With
    'Appending history into a section in the reply....................................
    Dim colorObject As NotesColorObject
    Set colorObject = session.CreateColorObject
    colorObject.NotesColor = COLOR_Blue
    Call rtItem.BeginSection(doc.From(0), richTitle, colorObject, True)
    Call rtitem.AppendRTItem(tmpItem)
    Call rtItem.EndSection
    Call reply.MakeResponse (doc)
    'Now remove the tmpitem
    Call reply.RemoveItem("tmpItem")
    Call reply.computewithform(False, False)
    'Release Memory..................................
    Set templatedoc = Nothing
    Set doc = Nothing    
    Set uidoc = ws.EditDocument(True, Reply)
End Sub

There is little error trapping, and I've loosely formatted the history - you can indent it with a paragraph style.  If the currently opened email is not saved or is edited, then you may want to remark out the line: uidoc.close, since that will trigger a "do you want to save?"

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts



Thank you so much for your time and response.  This worked great.  if I could give you more than the 500 I would!


I should also add that your explanations were so helpful and thorough.  Big help to a Lotus newbie like me.  I really can't say enough!

You're welcome!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.