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)

Search this blog 


    About IBM Privacy Contact