Create and populate stationery in lotusscript

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:
                  templateName
                  templateDescription
                  Body

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


Thanks!
KDragoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

marilyngCommented:
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 :)
0
KDragoAuthor Commented:
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.

Kim
0
KDragoAuthor Commented:
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
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

marilyngCommented:
KDrago,
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 ;)

Simpler...

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
            Else
                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    
    uidoc.Close
    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?"



0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KDragoAuthor Commented:
marilyng,

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

0
KDragoAuthor Commented:
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!
0
marilyngCommented:
You're welcome!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.