Linking documents.


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?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Z_BeeblebroxAuthor Commented:
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.


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)
Z_BeeblebroxAuthor Commented:
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?

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.

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

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.
OK, I got it... Queryopen won't work because the method we need to open the new document won't work there.  This is the Postopen event of the "don't open me" form... it's mighty quick and the user shouldn't know that anything else was ever opened.

Sub Postopen(Source As Notesuidocument)
     Dim ws As New notesuiworkspace
     Dim sess As New notessession
     Dim doc As notesdocument
     Set doc = source.document
     If Not (doc Is Nothing) Then    
          Dim target As notesdocument
          Dim openit As notesuidocument
Set target = sess.CurrentDatabase.GetDocumentByUNID(doc.parent(0))

Set openit = ws.EditDocument(True, target)

Call source.close

  End If
End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Z_BeeblebroxAuthor Commented:
Excellent solution. It works perfectly.


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.