[Answered] How to access parent document properties from Form PostOpen event?

In Notes client, I’m trying to add arbitrary text to new Reply/Forward documents based on their parent document properties.

My workaround to create a field with default value:

@GetDocField(@InheritedDocumentUniqieID;“ParentFieldName”)

It works on reply messages, because forms “Reply” and “Reply with History & Attachments” have OnCreate “Formulas inherit values from selected document” option set, but on Forward documents, @InheritedDocumentUniqieID is empty.

Is there a way to access parent document properties using LotusScript, from Form PostOpen event?

Subject: Not in Postopen, but you can use Queryopen…

…since the document hasn’t opened yet, the “current document” in the UI is whatever document you composed it from. So the Queryopen event can save information in global variables that the Postopen event can read.

Subject: Am I missing something?

Thanks, Andre, but it doesn’t seem to work.

When forwarding a message, in Memo Form subroutine:

Sub Queryopen(Source As NotesUIDocument, …)

'Added next 3 lines

Dim ws as New NotesUIWorkspace

Dim uidoc as NotesUIDocument

Set uidoc = ws.CurrentDocument

Source.Document is Nothing

uidoc is Nothing

Subject: CurrentDocument should work…

…but when I try it, I get the same result. But code in the Initialize event seems to work.

BTW don’t forget that you can forward a document from a view, so don’t assume there’s a current UIdoc. Check the NotesUIView.caretnoteid also.

Subject: Solution found

Posting this just in case someone else will struggle with the same problem.

The problem: I need to access originating document properties before the forwarded document is saved/sent.

Thanks to Andre’s suggestions, here is the solution:

In Initialize method of Globals(Memo), create a NotesUIWorkspace, check if its current view.

If it is not null, use CurrentView.CaretNoteID to access current document in a view. Works for all views and folders in my environment.

If CurrentView is null, use CurrentDocument.Document to access current document.

Store the property globally.

In QuerySave/QuerySend events, use the globally stored property.

Subject: One warning about this approach…

If you’re waiting for Querysave/Queryclose to make use of the stored value, the user may meanwhile have closed the original document, so your NotesUIDocument object may no longer be valid. But the NotesUIDocument object you got from it initially, I think might still be valid.

Subject: Never considered caching the ui doc…

… because I needed only several properties of the back-end document, but I will definitely give it a try.

Thanks!

Subject: Current UI document is not always the one the action was applied to…

In general, the suggested approach works, except in the cases below:

  • Current UI doc can be Nothing.

Select a document in Inbox, click either “New” or “Forward”, then close the new doc without saving/sending it. Without changing the focus in Inbox, click “Forward”. The current UI doc is Nothing.

  • Current UI doc can point to wrong document.

Select a document in Inbox, click either “New”, “Reply” or “Forward”. Do not close the new doc, go back to Inbox. Without changing the focus, click “Forward”. The current UI doc is the newly opened document.

If the focus changes to another document in Inbox, in both cases current UI document is the correct one.

Rephrasing the original question:

Any way to access original document properties from a forwarded document, before the forwarded doc is saved/sent?

Subject: current ui doc stuff

  • Current UI doc can be Nothing.That’s exactly what I said in my last post, and it’s why you have to check the CaretNoteID and NotesUIView.
  • Current UI doc can point to wrong document.

That sounds like a bug, but once again, you can maybe work around this by checking the NotesUIView and caret document first.

The easy way you’re looking for, does not seem to exist.