How can I change uidoc to be the opened document (docLinked) instead the email?

When somebody click on a document link via email I need to log when user open the document.

I use uidoc (notesuidocument) to log the info but when user open the doc via email (docLink), uidoc.form = Memo !.. how can I change uidoc to be the opened document (docLinked) instead the email?

Note: The code works great when user open a doc from the application but not from email docLink

Thank in advance!

Subject: Event code is passed a Source argument

which is the current document that’s being opened, whatever. You should always use this argument in event handlers, not wksp.CurrentDocument.

Subject: I used On Event from LibScript

Right!It is exactly what we do

The form has it to declare LibScript

Option Declare

Use “LogP”

’ script from LibScript “LogP”

Sub Initialize

Dim ws As New NotesUIWorkspace

Set uiDoc = ws.CurrentDocument

On Event Postopen From uiDoc Call LogEvent

On Event PostSave From uiDoc Call UpdateEvent

’ but from mail, … On Event doesn’t do anything… we must add this

’ LogByView is a boolean (public).

If Not logByView Then

Call LogEvent(uidoc)

End If

End Sub

What I’m doing wrong?

Subject: What you’re doing wrong, as I said, is using wksp.CurrentDocument

This property doesn’t mean “the document containing this code,” it means “the document that has focus.” In the Initialize event the new document window didn’t open yet, so the current document is the memo document. So what you’re actually doing, is setting the event handler in the memo document. So the events of the memo document will now call code in your newly opened document (which is not getting called because the memo document is already open and not being edited, so its Postopen and Postsave events aren’t triggered).

It’s actually occasionally useful to set cross-window events this way, but it’s clearly not what you intended in this case.

Is there some reason you can’t just put your code in a form event (or a subform event)? Why are you doing things in this odd way?

Subject: 20 forms in 10 db

This LScript log is used by about 20 forms in the db.

Each time we’ll need to change the Log code we must change it on 20 forms event (in 2 event for each form)!

Is that any other solution exist?

Subject: On having an event call a subroutine

So your event code on the form is one line, calling the subroutine in your LotusScript library. Why should you ever need to change that?

Subject: Do I need to use another doc class than uidoc?

Yes it isThe forms event is on LScript Library

with param:


Set uiDoc = ws.CurrentDocument

On Event Postopen From uiDoc Call LogEvent

On Event PostSave From uiDoc Call UpdateEvent


Sometime, we need to make some change in the log (some field added, or any other reasons…)

I’m new in this company and I’m here only for a short time so I don’t know exacly why they want it like this…

I’m here to fix some bugs and one of them is the log not append when user enter in doc via email docLink…

Honestly, I’m not sure if a solution exist with this context…

I already propose to put the script on Event Form. But this will be give some trouble for any little change in log because they must change it on many form and/or many event.

Do you think about something?

Question

Why when the doc is opened (even if they opened from doclink by email) the PostEvent script for that doc is not used in ScriptLib?

(I understand that the email is used first but once the doc is opened… do I need to use another doc class than uidoc?)

Thanks a lot it’s really appreciate

Subject: There’s nothing to maintain…

Here is the form event I’m suggesting you write:

Sub Postopen(Source As Notesuidocument)

Call LogEvent(Source)

End Sub

and just get rid of the Initialize code. Do you see anything in the above code sample which specifies a field name? Do you see anything you would ever need to change for any reason?

I’m sorry, but I cannot help it that you’re trying to run code to get the current uidoc when the current uidoc does not yet exist. There’s no way to do this in the Initialize event that will work in all cases.

Subject: THANKS! I use uidoc.previewpane …!

Sorry, I forgot to tell something…It’s exacly want have done in my first day here… but many form who need to be log contains an embeded view and a when user click on a doc via this embeded view they call doc preview and the event PostOpen occur (When we put the code on Form event PostOpen instead the LibScript)… we have too many log (opened & preview doc) and it’s not acceptable for us.

We want only log of full opened document not doc preview.

I found the solution!

If Not uidoc.InPreviewPane Then

… Sorry for all this!

… I just realise when I write this that I have the answer just before my nose!

Thanks for all

Subject: uidoc.InPreviewPane doesn’t work in embeded view?

Sorry… I think the code working but Now I saw it doesn’t :frowning:

now I put the code on 25 form

event PostOpen

Call logEvent(Source)

When I Open a doc who contains an embeded view AND embeded Editor, I preview the others doc … the code log it all … but I don’t want log in preview mode (from embeded Editor)

I put this code to prevent it


Sub LogEvent(uiDoc As NotesUIDocument)

Dim doc As NotesDocument

Dim s 	As New NotesSession

Dim curdb As NotesDatabase



Dim serveurCN As String

Dim serveur As String

Dim path As String



On Error Resume Next



MsgBox Str(uidoc.Inpreviewpane)

’ *************************************

If Not uidoc.InPreviewPane Then 

	Set curdb = s.Currentdatabase

In the msgbox uidoc.Inpreviewpane always = false

even it I access from embeded Editor :frowning:

It’s append always when the code is on Form event PostOpen or PostSave

But not append when we use LibScript on initialize

But when we use LScript, the doc is not log when we access via email doc link…

Any suggestion??

Subject: I think there may be some confusion about which document you’re working with in different circumstances

Anytime you’re using a uidoc, I think you had better put up a messagebox with the windowtitle and noteID of the uidoc, so that you know for sure which one you’re working with.

I haven’t tried it, but I would guess that the reason InPreviewPane returns False when used on a document in the embedded editor, is that the embedded editor is not a preview pane. There doesn’t seem to be a function to do this test.

However, I notice about documents in an embedded editor, that when the document opens it does not have focus. The containing document (with the embedded view and editor in it) has focus. Therefore, perhaps you could take advantage of the fact that there’s a difference between the currentDocument and the Source argument, to determine whether the document being opened, has focus. When it doesn’t, or is in the preview pane, is when you don’t want to write a log entry.

Sub LogEvent(Source As NotesUIDocument)

Dim ws As New NotesUIWorkspace

if Source.InPreviewPane Or Not (Source Is ws.CurrentDocument) Then

  Exit Sub ' don't log unless doc is opened in its own window.

End If

This also suggests that the reason putting the code in the Initialize event works for documents in the embedded editor (does not log) is totally by accident. Once again here, the Initialize event reads the wrong document by mistake and sets the Postopen and Postsave events of the containing document rather than those of the document in the embedded editor. This means the events can still trigger at unintended times, e.g. if the document with the embedded elements is edited and saved.

Incidentally, I don’t know what your customer’s application is, but it strikes me as silly to log every time a user opens a document, only when its opened in its own window. Because I opened a document, that doesn’t mean I read that entire document. Or, just because I opened a document in the preview pane instead of its own tab, what’s to say I didn’t carefully read the whole document? I read my email, for instance, almost entirely in the preview pane. I read it, answer it, delete or file it, without ever opening it in its own tab. What does that log entry actually mean? It doesn’t tell you anything about whether the user actually read the document, forwarded it, printed it, sent it to wikiLeaks, or what have you.

Subject: uidoc is always CurrentDocument

First of all… Thanks a lot AndreI know it’s a part of time that I really appreciate from you…

+++

I put the code like you said:


Sub LogEvent(uiDoc As NotesUIDocument)

Dim ws As New NotesUIWorkspace

’ MsgBox Str(uidoc.Inpreviewpane)

If uidoc.InPreviewPane Or Not (uidoc Is ws.CurrentDocument) Then

	Exit Sub

End if


But we always log with uidoc.

It’s normal because all subdoc has PostOpen with: call logEvent(source).

The users can access the docs via a view or a main doc, attachment (mail), and searchby NoDoc.

In all situations it can be a main doc or subdoc.

For me it’s also a non-sens to know when somebody open a doc (thats mean the doc can be read) but not in preview (thats also mean the doc can be read).

But one of the reason it that’s because in PREVIEW MODE WE NOT SHOW ALL INFOS in the documents… (only when it’s open).

Once again, Thank you for your support!

Subject: with Form event PostOpen we log too much doc because doc preview.

A person in the company told me that we absolutly need this log code in LScript because many form who need to be log contains an embeded view and a when user click on a doc via this embeded view the pcall preview and the event PostOpen occur (When we put the code on Form event PostOpen instead the LibScript)… we have too many log and it’s not acceptable for us. We want only the log of the full opened document not doc preview.

Thanks