Create and populate stationery in lotusscript

Posted on 2006-03-28
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.

Question by:KDrago
    LVL 18

    Expert Comment

    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 :)

    Author Comment

    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 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.


    Author Comment

    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
    LVL 18

    Accepted Solution

    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?"


    Author Comment


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


    Author Comment

    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!
    LVL 18

    Expert Comment

    You're welcome!

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Notes Document Link used by IBM Notes is a link file which aids in the sharing of links to documents in email and webpages. The posts describe the importance and steps to create a Lotus Notes NDL file in brief.
    Article by: Rob
    Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    728 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