lotus-noteslotus

NotesDocument opens twice


I have an application that uses 2 servers and has 2 databases. Server 1 - Main application Server 2 - Calendar

When launching a document in the main application, I have a link to the calendar entry. This opens the calendar entry on the calendar server. There is a link in the calendar entry that launches the document in the main application.

This action is performed using the notesuiworkspace.editDocument function.

The problem I have is that in my scenario above, I have the main document open in the application (1 document). I then click on the button to launch the calendar entry (I now have 2 documents open, the document in the main application and the corresponding calendar entry). If I then click on the open main document button, it opens another copy of the main document. If the user is unaware they then cause save conflicts.

This has occurred for several versions of Notes, currently on 10.

Code from Main Application Server 1 docuemnt to open calendar entry:

Set uidoc = ws.CurrentDocument
Set doc = Srv1.GetDocumentByUNID(uidoc.FieldGetText("CalenderUNID")
If Not (doc Is Nothing) Then
  Set uidoc = ws.EditDocument(True, doc)
End If      

Code from Calendar Entry to Main document on Server1

sID = uidoc.FieldGetText("MainUNID")
Set doc = Srv1.GetDocumentByUNID(sID)
If Not (doc Is Nothing) Then
  Call uidoc.Close(True)
  Set uidoc = ws.EditDocument(True, doc)
End If

Solution

  • Please check the documentation for "EditDocument" in NotesUIWorkspace:

    Set notesUIDocument = notesUIWorkspace .EditDocument( [editMode] , [notesDocument] , [notesDocumentReadOnly] , [documentAnchor$] , [returnNotesUIDocument] , [newInstance] )

    You see, there is an optional parameter "newInstance". And if you read further it sais:

    newInstance

    Boolean. Optional. If True (default), opens a new instance of notesDocument (parameter 2) in the UI. If False, changes focus to an existing instance of notesDocument if one exists, or to a new instance if one does not exist. This parameter does not apply if notesDocument is not specified or the document has a target frame.

    Just change your code accordingly:

    Set uidoc = ws.EditDocument(True, doc,False,"",True,False)
    

    But beware: There is a (little) bug with the "newInstance" flag: If you create a new main document and save it. Then open the calendar document and click the link back to the main document, then there will always be a second window with the main document unless you closed and reopened the main document in the meantime... A "new" document that has not been closed and reopened after saving is not recognized by the newinstance flag...