IBM®
Skip to main content
    Country/region select      Terms of use
 
 
   
     Home      Products      Services & solutions      Support & downloads      My account     
 
developerWorks
AIX and UNIX
Information Mgmt
Lotus
New to Lotus
Products
How to buy
Downloads
Live demos
Technical library
Training
Support
Forums & community
Events
Rational
Tivoli
WebSphere
Java™ technology
Linux
Open source
SOA and Web services
Web development
XML
My developerWorks
About dW
Submit content
Feedback



developerWorks  >  Lotus  >  Technical Library
developerWorks



Tips from LDD

Adding an autosave feature to your Notes mail file


Tip submitted by
Andre Guirard


Level: Intermediate
Works with: Notes/Domino
Updated: 08/04/2003

Related link:
More Tips from LDD


Have you ever wanted an "autosave" feature in Notes mail, so you don't lose your magnum opus memo in a crash (or via fumbling fingers)? You can customize your mail file to save a draft at an interval you specify.

Open your mail database in Domino Designer and open the Script Library view. Select CoreEmailClasses, then choose Design - Design Properties. The CoreEmailClasses script library is the library in which Lotus intends customization of the Notes memo event code. In the Design Document Properties box, select the Design tab, and enable "Prohibit design refresh or replace to modify."

Next, double-click the script library. In the Declarations section, add the following code:

' (Declarations)
Dim autosaveTimer As Variant
Dim autosaveUidoc As Variant
Dim autosaveInterval As Double

Sub AutosaveInit(Source As NotesUIDocument)
    Dim formname As String
    If source.EditMode Then
      formname = source.Document.Form(0)
      If Not (formname = "Memo" Or formname = "Reply" Or formname = "") Then Exit Sub
      If profile Is Nothing Then
      Set profile = Source.Document.ParentDatabase.GetProfileDocument("CalendarProfile")
      End If
      If profile.GetItemValue("AutosaveMemo")(0) = "Y" Then
      Dim interval As Double
      interval = profile.GetItemValue("AutosaveInterval")(0)
      autosaveInterval = interval * 60.0 ' seconds
      Set autosaveTimer = New NotesTimer(autosaveInterval)
      On Event alarm From autosaveTimer Call AutosaveNow
      Set autosaveUidoc = Source
      End If
    End If
End Sub

Sub AutosaveNow(Source As NotesTimer)
    Source.Enabled = False ' so no other interrupts occur while we're processing this one.
    Dim ws As New NotesUIWorkspace
    Dim uidoc As NotesUIDocument
    On Error Goto oops
    Set uidoc = ws.CurrentDocument
    If uidoc Is AutosaveUidoc Then
      ' the user is still in the document editing window
      If uidoc.CurrentField = "Body" Then
      Source.Interval = autosaveInterval
      AutosaveUidoc.Refresh(True)
      Call AutosaveUidoc.Document.Save(True, False, True)
      Print "Autosave at " & Format(Now, "Medium Time")
      Else
      ' the cursor isn't in the Body field. try again later (workaround for Notes client bug).
      Source.Interval = 30 ' seconds
      End If
    Else
      ' the uidoc is no longer the current window. Don't bother to try to save, but check again soon.
      Source.Interval = 30 ' seconds
    End If
    Source.Enabled = True
    Exit Sub

oops:
    Print "Autosave failed; deactivating for this document. (error " & Err & " line " & Erl & ")"
    Exit Sub
End Sub

In the PostOpenExtension subroutine, just before the line "PostOpenExtension = True", insert the following call:
    Call AutosaveInit(Source)

To control autosave from the Preferences dialog box in Notes mail, change the (Calendar Profile) form. In Domino Designer, open the Forms view, select the (Calendar Profile) form, and enable the Prohibit design refresh option as before. Then add the Autosave tab as shown below. Follow these steps:
  1. Select the Basics tab, then choose Table - Append Row.
  2. In the Table Properties box, select the Table Rows tab and enter Autosave in the Tab label and caption field.
  3. Click the Autosave tab, then choose Text -Text Properties.
  4. Select the Paragraph Hide When tab in the properties box.
  5. Remove any hide attributes from the tab.
  6. Add the two fields AutosaveMemo and AutoSaveInterval to the tab. The following screen shows both fields in a nested table.

(Calendar Profile) form

The two fields are defined as follows:
  • AutosaveMemo
    This is a checkbox field and is editable. Select the Refresh on keyword change option and in the keyword list add Autosave Enabled|Y.
  • AutosaveInterval
    This is a number field and is editable. Specify 10 as the default value. Add the following Input Translation formula to the field:

    @If(AutosaveMemo = ""; @Success; AutosaveInterval = ""; "You must enter the autosave interval."; AutosaveInterval < 1; "Autosave interval may not be less than 1 minute."; @Success);

    Apply the following hide-when formula to the field:

    AutosaveMemo != "Y";

After you add the tab, save and close the form. To enable autosave, open your mail database. Click Tools on the action bar and select Preferences. In the Preferences dialog box, select Autosave.

Note: if you upgrade to a new version of the Notes mail file design, you need to manually merge your changes with any updates Lotus has made.


SUBMIT YOUR TIPS!
We encourage you to send us your tips (You can also click the "Would you like to submit a tip?" graphic below.) Your tips can be anything you've discovered about any Lotus product. The most important thing is that your tip be interesting, useful, or handy. And be sure to include complete information about how your tip works. For ideas, take a look at our tip archives. If we publish your tip, we'll send you the IBM Redbooks Lotus Collection on CD.






Would you like to submit a tip?
    About IBM Privacy Contact