Autoclosing a document

How to get a system to close a document.

View expert feedback to this tip.

I had a customer who requested that a document be automatically closed by the system. To do this, I used the Notes Timer (and a field in the DBProfile) so users can change the timeout interval.
I created a subform called TimerSF.

Single Field "DocTimeout"
Computed Number 
@Text(@GetProfileField( "DBProfile" 
; "DocTimeout"));

Dim elapsedTime As Integer
Dim elapsedTimer As NotesTimer
%INCLUDE "lsconst.lss"

Sub Postopen(Source As 
 Dim backdoc As notesdocument
 Set backdoc = source.Document
 Set elapsedTimer = New NotesTimer
(60, "Elapsed time since opening document")
 elapsedTime = 0
 On Event Alarm From elapsedTimer 
Call elapsedTimerHandler
 If backdoc.docTimeout(0) = "" 
Or Cint(backdoc.docTimeout(0)) = 0 Then
  elapsedTimer.Enabled = False
  Print "Timer Disabled"
  elapsedTimer.Enabled = True
  Print "Timer Enabled"
 End If
End Sub

Sub Postrecalc(Source As Notesuidocument)
 elapsedTime = 0
 'Reset Counter if doc is being edited
End Sub

Sub elapsedTimerHandler
(Source As NotesTimer)
 Dim workspace As New NotesUIWorkspace
 Dim uidoc As NotesUIDocument
 Dim backdoc As notesdocument
 Set uidoc = workspace.CurrentDocument
 Set backdoc = uidoc.Document 
 elapsedTime = elapsedTime + 1
 If elapsedTime > Cint(backdoc.
DocTimeout(0)) Then
  Call uidoc.Save  
  Call uidoc.Close
  Print "Doc Closed as Timeout period Expired"
  Print Cstr(backdoc.DocTimeout(0)) + " 
< " + Cstr(elapsedTime)
 End If
End Sub


  1. Don't use a field on the form for loading the profile value -- do it in the code and store the value in a global. More efficient and hack-proof.

  2. If you do use a field, at least make it Computed for Display -- there's no need to store this value.

  3. Don't save changes to a document without first checking whether it's in edit mode.

  4. Are we really sure we want to save changes without prompting the user?

  5. This may crash the user's workstation in the following scenario: fails because of input validation. Messagebox with validation error message. User doesn't click OK within the interval to the next timer event (one minute). Notes crashes because the timer event happens when the previous timer event isn't done yet. To prevent this, the code should disable the timer before doing anything that might prompt the user.

  6. Timer event uses NotesUIDocument.CurrentDocument -- this returns the current document that's open onscreen. Since the user can open additional windows, the timer document may be open but not be the current window. The event code may therefore save and close a document in another window that it wasn't meant to mess with.

Do you have comments on this tip? Let us know.

Dig Deeper on Lotus Notes Domino Administration Tools

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...