andyleeyuan
andyleeyuan

Reputation: 21

How can Lotus Notes detect whether a document is currently being opened?

As title.

How can Lotus Notes detect whether a document is currently being opened?

The solution should without "Document locking" because of User's User needs.

I have 1 maindoc and 1 subdoc, but subdoc and maindoc are not parents.

I use the "IsUIDocOpen" but it just worked at currentdocument.

Is there any other way to do this?

Upvotes: 1

Views: 928

Answers (1)

Tode
Tode

Reputation: 12060

If you ask just for one client, then this is doable without document locking, but it needs some advanced techniques:

You can use NotesUIWorkspace to get a currently open document for any given backend document if you set parameter "newInstance" to false.

To get the currently open document (as uidocument, but of course you can use .Document property to get NotesDocument from it) you use the following code. If it returns nothing then the document is not open:

Dim ses as New NotesSession
Dim ws as New NotesUIWorkspace

Dim docToGetFrontendFor as NotesDocument
Dim uidoc as NotesDocument

Set docToGetFrontendFor = .... 'somehow get the document you wanna have the frontend for

Call ses.SetEnvironmentvar( "PreventOpen" , "TRUE" )
Set uidoc = ws.EditDocument( False, docToGetFrontendFor, False, "", True, False )
If not uidoc is Nothing then '-document was open already
    '- do whatever with the frontend- document

Why the ses.SetEnvironmentvar( "PreventOpen" , "TRUE" )?

The EditDocument opens the document regardless of it being open already or not.

You need to prevent the document from opening, if it is not already open. Therefor you manipulate the "QueryOpen"- Event of the Form of the document:

Sub Queryopen(Source As Notesuidocument, Mode As Integer, Isnewdoc As Variant, Continue As Variant)
  Dim ses as New NotesSession
  Dim strPrevent as String
  strPrevent = ses.GetEnvironmentstring( "PreventOpen" )
  Call ses.SetEnvironmentVar( "PreventOpen" , "" )
  If strPrevent = "TRUE" Then Continue = False
End Sub

So: The document does NOT open, if PreventOpen is set, so if it is not already open it will stay closed.

This approach has one big downside: The Notes Client has a "BUG": If you open a document and save it and then open it again with my code, then it will Open in a second window DESPITE the parameter "newInstance" set to false unless you closed and reopened that document.

Explained:

  • Create Document
  • Save document
  • Close document
  • Reopen document
  • Use my code ==> Works as the code just "reuses" the window

  • Create Document

  • Save document
  • Use my code

==> Will try to open a second instance for the document and then return NOTHING as this new instance does not open because of the code...

Upvotes: 1

Related Questions