Link to home
Start Free TrialLog in
Avatar of Z_Beeblebrox
Z_Beeblebrox

asked on

Linking documents.

Ok,

This is the third or fourth time that I have posted this question in one form or another, and I have still been unable to resolve it. The solution to the problem that I am currently trying to implement requires that when a user tries to open a document in a database that uses a particular form, that they get "redirected" to a different document. So far, I have been unable to implement this in a way that is invisible to the user. My current solution uses @functions in the queryopen of the original to first open a view to a selected document, then open that document. This has the unfortunate problem of opening 2 more windows than I want: the new view and the original document. When I try to add a fileclosewindow command to the query open, I get a Dr. Watson error and Notes dies. When I put it in PostOpen, nothing happens. What can I do?

Zaphod.
Avatar of melbor1
melbor1

Why don't you run an agent on all the doc's that use that form and delete the form that it has and set the form to the one you want.

If you need help w/the script, let me know.
Are you somewhat comfortable with LotusScript?  

If so, I would suggest sticking with the Queryopen form event.  What you probably want to do there is get a handle to the document you *do* want to open, set 'Continue = False' so the current operation won't actually get around to opening the selected document, and then open the document you do want through its handle.  Or reorganize this if you like... it shouldn't really matter.

Basically, there is no good/safe way to tell Notes "whoops, don't open this document!" in the formula language.  You can stop things from happening by setting 'Continue' to false--available wherever you see 'Continue' as a parameter to the sub...
A trick I have used in the past is to re-open the view and set the "newInstance" parameter to "0", then do a FileCloseWindow.  That would close at least one of your extra windows.

However, if you do know LotusScript (or are willing to learn it), I prefer sk5t's solution.
Avatar of Z_Beeblebrox

ASKER

I am somewhat familiar with script, although I would appreciate it if you would give me a start, since I am not sure how to open a document in script. Any help would be appreciated. To help you out, inside the document I don't want to open, I have a field which stores the unique ID of the document I do want to open. Alternatively, although not preferably, the document can be found via the first sorted column in a view.

Thanks,

Zaphod.
You can get a handle to, and open, the doc by its UNID like so -- if the target UNID is stored in a field called "TargetUNID":


Dim ws As New NotesUIWorkspace
Dim session As New NotesSession
Dim uidoc As NotesUIDocument
Dim targetdoc as NotesDocument
Dim doc as NotesDocument

Set uidoc = ws.CurrentDocument
Set doc = uidoc.Document

Set targetdoc = session.CurrentDatabase.GetDocumentByUNID(doc.TargetUNID(0))

' stop opening this thing
Continue = False

' and open this thing instead for editing
Set uidoc = ws.EditDocument(True, doc)
Errr, whoops, make that last line:
Set uidoc = ws.EditDocument(True, targetdoc)
I get the error "Object variable not set." and the document I don't want open opens. I kept your script exactly the same, except for the line with the UNID, which I changed to:

Set targetdoc = session.CurrentDatabase.GetDocumentByUNID(doc.Parent(0))

since Parent is the name of the field with the ID in it. I also made the correction you mentioned. Any ideas?

Zaphod.
Instead of setting uidoc, why don't you guys put the new document to open in a dialogbox.  It will be cleaner than having another document open in the ui.

R
I want to transferal to the other document to be invisible to the user, therefore a dialog box will not meet my requirements.

Zaphod.
Gimme a few minutes to do some quick testing.  (Hey, I don't wake up for another few hours yet... :-)  )

First thing I did wrong is setting uidoc to the current document -- much cleaner to refer to it as 'source' since it's a parameter to the queryopen sub.
ASKER CERTIFIED SOLUTION
Avatar of sk5t
sk5t

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Excellent solution. It works perfectly.

Thanks,

Zaphod.