Skip to main content
    Country/region select      Terms of use
     Home      Products      Services & solutions      Support & downloads      My account     

developerWorks  >  Lotus  >  Forums & community  >  Best Practice Makes Perfect

Best Practice Makes Perfect

A collaboration with Domino developers about how to do it and how to get it right in Domino

Here's a question I recently got in email. Supposing you have an action to automatically compose an email, but you want to let the user edit the memo before it's sent. Using LotusScript, you create the back-end NotesDocument in memory, assign all the fields including Body, then use NotesUIWorkspace.EditDocument to open it. Easy, right? Well, unless the user has an automatic signature.
The question was:
When you open the memo, why in the name of all that's holy does the Memo form insert the user's signature block at the top of whatever content your script generated?
It's done this way because it usually makes sense. When you reply to or forward a document, you want the thread or the forwarded document at the bottom, under your signature block. It just turns out to be inconvenient for those applications where you would like to write a letter for the user and let them adjust its contents.
I've suggested to the folks who manage the mail template that it might be nice to make the Memo form support an option where you can tell it at runtime whether the signature is wanted at the beginning or the end (for instance, you could set an item as a signal, which the code in CoreEmailClasses would notice). In the meantime, here are some ideas for workarounds, with their respective disadvantages.

Approach Details Drawbacks
Use UI functions to compose the memo Call @Command([Compose]; @MailDBName; "Memo"), then use additional @Commands to navigate to the body field and fill in the text of the memo. Only works for text and simple formatting. Can't add a paragraph break; just line breaks.
Create your own memo form In whichever application generates the content, create a form called Memo which is a copy of the standard Memo form (perhaps greatly simplified) and inserts the user's signature in the right place. Too much work. Must maintain in synch with Notes mail forms (e.g. in case a new file type becomes supported for signatures). The code for inserting a signature is complex. Yes, you can just copy it, but complex means likely to change.
Customize CoreEmailClasses in mail template Make CoreEmailClasses look for a special flag item, as discussed above, and if it's present, go to the end of the memo before inserting the signature. Delete the item when done to prevent it cluttering the mail file. Must reapply customization with each version of mail template.
Temporarily suppress signature Before calling EditDocument, modify the user's profile document to specify no signature. Afterwards, return the signature to whatever it was before. This can be done without saving the profile document. The memo doesn't contain a signature.

For some applications, the last option may be just fine. For example, if the email is a report that users need to send in to some central address for manual processing, the people who do this processing don't care about the user's tiny photograph and clever motto. And the code for this lets me point out a useful feature of profile documents, so I'm attaching the code, with my comments. The critical section for our purposes is this:
1.        Dim dbMail As New notesdatabase("", "")
2.        dbMail.OpenMail ' Locate the user's mail file.
' code omitted here to create memo in back end, set fields, and create the Body contents.
3.        Dim bSuspendSig As Boolean
4.        Dim docProfile As NotesDocument
5.        Dim SigOption
6.        Set docProfile dbMail.GetProfileDocument("CalendarProfile")
7.        sigOption = docProfile.GetItemValue("SignatureOption")(0)
8.        If Isnumeric(sigOption) Then
9.        If sigOption <> 0 Then ' there is an automatic signature
10.        docProfile.SignatureOption = ""
11.        bSuspendSig = True ' remember to restore it later.
12.        End If
13.        End If
14.        Set uidocNew = wksp.EditDocument(True, doc, , , , True)
15.        If bSuspendSig Then
16.        docProfile.SignatureOption = sigOption
17.        End If

Line 6
gets the user's mail preferences, which are stored in a profile document named CalendarProfile.
The SignatureOption item of the profile tells whether the user has enabled automatic signature insertion (line 7). If it is a number and not zero, the user has selected to insert a signature.
For this memo only
, we want to disable signature insertion, so line 10 sets it to blank.
Line 14
opens the memo editing window, displaying the back-end document with the rich text we created somewhere between lines 2 and 3. The LotusScript code in the Memo form reads the profile value we just wrote, and concludes there is no automatic signature for this user.
Line 16
restores the previous value of the item, so the user will get their signature later, when they compose a memo manually.
The code doesn't call Save on the profile document -- why not? Profiles are cached in memory, so if our code changes an item, other code that reads the profile document will see that change. Normally, when you make a change to the profile document, you want to save, so that the change isn't lost when you close Notes. In this case, we don't want to keep the change, and anyway the profile ends up with the same value it had at the start, so saving would be a waste of time.
The full code is available here: nosig.lss

Andre Guirard | 12 March 2007 10:45:00 AM ET | Plymouth, MN, USA | Comments (5)


1) Do you sign at the top?
Martin Leyrer | 3/12/2007 5:16:33 PM

Andre, thanks for the "trick". That is a nice idea.

Let me just add something regarding replying "on the top". This may make sense in Notes or other Businnes-Grade email clients, but "on the net", a bottom or inline quoting style and therefore quotes at the bottom are more "en vouge".

See { Link } and { Link }

2) Do you sign at the top?
Bart | 3/16/2007 7:14:35 AM

Thanks Andre, great tip.

Don't you want to use the field "EnableSignature" on the profiledoc instead of "SignatureOption" (which both are text)? Or am I overlooking something?

3) re: Do you sign at the top?
Andre Guirard | 3/18/2007 9:15:04 AM

Looks like either one would work... no strong reason to choose one over the other as far as I can see.

4) Re:Do you sign at the top
Djóni á Boðanesi | 10/13/2007 10:18:26 AM

Thanks for the article.

I used the last approach, to supress or block the users signature option permanently, and rather paste data with rich formatting from an organisation database to the profiledocument of the user, thus giving a great signature, personalized by users name etc. but centraly administered with legal disclaimer text and advertizing in rich text.

But still have the drawback of the third aproach, having to copy the customization to each new version.

5) Do you sign at the top?
Ingo Beyer | 8/6/2008 4:30:55 AM


Thank you for sharing this code example.

Maybe you have a bug in your blog software. The last line of your posting shows:

"Andre Guirard | 12 March 2007 10:45:00 AM ET | Plymouth, MN, USA | Comments (2)"

I count 4 comments without mine.

My true reason for my comment is a question.

How I can append text after the table?


Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)

Call rti.BeginInsert(rtnav)

Call rti.AppendText("Time Savings (hrs)")

Call rti.EndInsert

rti.appendText("This is a Test")

does not work.

I have solution like this


Call rti.AppendText("Time Savings (hrs)")

Call rti.EndInsert

'/ append text after the table...

Call rti.addnewline (3)

Call rti.AppendText(docProfile.Signature_1(0))

Call rti.BeginInsert(rtnav)

Call rti.EndInsert

It works, but it seems strange and not right.

I hope you know the correct solution.

Thank you for your patience.


Ingo Beyer

PS: I posted a similar question on ldd.

{ Link }

6) modifying CoreEmailClasses
Joseph LeMay | 2/1/2011 1:31:56 PM

to make this modification, go to the InsertSignature subroutine of the UIMemoDocument Class. Look for the Select Case block, and under Case 1, you're just substituting an inserttext for a Fieldappendtext. This won't help you if you put your signature block in an HTML file or txt file, but it works for your basic text signature block. no need to do special flag item in this case.

If FromMailPreference Then Call Me.m_noteUIMemo.GotoField("Body")

Call Me.m_noteUIMemo.Fieldappendtext("Body",Me.m_strSignature)

If FromMailPreference Then Call Me.m_noteUIMemo.GotoField("Body")

7) correction to modifying CoreEmailClasses
Joseph LeMay | 2/3/2011 12:25:33 PM

So, if you do it the way I suggested in my previous post, you get your sig applied to the bottom of all emails, including replies, which makes them hard to read if you're following a thread.

here's a better way. Set the value of an item in your mail memo and use that to check which way you're doing it. In my case, the field name is "BuyoutRFP"

Case 1

If FromMailPreference Then Call Me.m_noteUIMemo.GotoField("Body")

'added by joe lemay to accomodate buyout RFP.

Dim buyoutRFP As NotesItem

Set buyoutRFP = ME.m_noteUIMemo.Document.Getfirstitem("BuyoutRFP")

If buyoutRFP Is Nothing Then

'just a regular mail memo

Call Me.m_noteUIMemo.inserttext(Me.m_strSignature)


'it's an RFP from Buyout DB. append the signature at the very end.

Call Me.m_noteUIMemo.Fieldappendtext("Body", Me.m_strSignature)

End If

If FromMailPreference Then Call Me.m_noteUIMemo.GotoField("Body")

 Add a Comment
Comment:  (No HTML - Links will be converted if prefixed http://)
Remember Me?     Cancel

Search this blog 


    About IBM Privacy Contact