Creating Response Document for document opened from embedded view

Scenario: I have a series of Action buttons called DbLinks that open summary documents in several databases. Each summary document has a single category embedded view that returns all documents pertaining to a customer based on a CustomerNumber key.

When I access this summary document in a different db, it opens fine.

When I access a summary document in the same db, it opens fine. But then, after opening a document from the embedded view, I am unable to create a response document to the newly opened document. It simply returns a new instance of the original document calling the response.

I have used the following code to create a response, save it, and then reopen. It works fine (according to the Debugger) until the last line. I am able to create the doc, it shows up as a response in the view, but when I try to open it for editing, it takes me back to the new instance of the original calling document.

Set newDoc = db.CreateDocument

newdoc.Form = “fNotes”

newDoc.Subject = “Notes Script Test”

newDoc.CustomerNumber = doc.CustomerNumber(0)

newDoc.Customer = doc.Customer(0)

newDoc.Contact = doc.Contact(0)

cd = Now

cn = doc.CustomerNumber(0)

newDoc.CreateDate = cd

Call newDoc.MakeResponse(doc)

Call newDoc.Save(True, True)

Set view = db.GetView( “NotesLU” )

key = cn+cd

Set newDoc2 = view.GetDocumentByKey( key, True )

Set uidoc2 = ws.EditDocument(False, newDoc2, False, “Subject”, True, True)

BTW - this code works fine at the top level, just not from a document opened from an embedded view.

Subject: Question?

If you had a action button with simple @Command([Compose]; “Responseformname”) on the form, will it create the response document?

Subject: RE: Question?

Yes - and originally that was what I was doing. It was when I ancountered the problems mentioned above - it didn’t work when creating from a document that had been opened from an embedded view - that I began trying alternatives to get around the problem.

Subject: Okay! Next question?

Can you create a response document from the main document without it being opened in an embedded view? Perhaps, the problem is not the embedded view?

Subject: RE: Okay! Next question?

Yes I can…let me give you a schematic:

Open an existing Contact document

Create a Note (response document) - code works fine

I decide I want to look at a list of all the other contacts for this Customer, so I open the “Summary Contacts” document which contains an embedded, single category view, displaying all the Contacts for that Customer based on the CustomerNumber.

I open another Contact document from the embedded view…I try to create a note, using the exact same code (it’s on the Action Bar)…instead of seeing a new, blank response document (Note), I get a new instance of the Contact form.

When I run the code in debugger, it shows the Note is created, made into a response to the Contact document, saved, recovered - I now have a handle on it.

But, as soon as the ws.EditDocument(…) line runs, I lose the handle on the response document, and the aforementioned new instance of the Contact document shows up on the screen.

Somehow I am losing the handle on the document opened from an embedded view, but I don’t lose the handle when the response is created from a document opened from a regular view.

I am a bit baffled.

Subject: Hmmm…

Try running the code from an action button on the form? I’m going to try to recreate your scenerio and see what kind’a results I get.

Subject: Thanks - I really appreciate it…

It is so weird. Why would it work on a document opened from a view, and not work from the same document when opened from an embedded view?

Subject: Say!

In your current formula what is doc2? It appears you lose the handle because there is no doc2?

Perhaps, I’m missing some code or something?

Subject: Here is the full code…I have tried several variations

Sub Click(Source As Button) Dim s As New NotesSession

Dim db As NotesDatabase

Dim ws As New NotesUIWorkspace

Dim doc As NotesDocument

Dim view As NotesView

Dim newDoc As NotesDocument

Dim newDoc2 As NotesDocument

Dim uidoc As NotesUIDocument

Dim uidoc2 As NotesUIDocument

Dim key As String

Dim cd As String

Dim cn As String



Set db = s.currentdatabase

Set uidoc = ws.currentDocument

Set doc = uidoc.Document

	

Set newDoc = db.CreateDocument

newdoc.Form = "fNotes"

newDoc.Subject = "Notes Script Test"

newDoc.CustomerNumber = doc.CustomerNumber(0)

newDoc.Customer = doc.Customer(0)

newDoc.Contact = doc.Contact(0)

cd = Now

cn = doc.CustomerNumber(0)

newDoc.CreateDate = cd

Call newDoc.MakeResponse(doc)

Call newDoc.Save(True, True)



Set view = db.GetView( "NotesLU" )

key = cn+cd

Set newDoc2 = view.GetDocumentByKey( key, True )

	Set uidoc = ws.EditDocument(False, newDoc2, False, "Subject", False, False)

End Sub

Subject: RE: Here is the full code…I have tried several variations

I hardcoded the key and was able to get past the ws.editdocument line. The response doc was created. I’m not sure my test duplicates yours (not sure what your NotesLU view contains.

More tomorrow…

Subject: NotesLU view

first sorted column is CustomerNumber and Now concatenated with no spaces.

Code works on normal documents…its the same document opened from an embedded view that doesn’t work.

Thanks for your help…talk to you tomorrow

Subject: RE: NotesLU view

“cn + cd” is not a concatenation; “cd” is not text and we don’t know what cn is (other than that it’s labelled “Customer Number”). IF “cn” is, in fact, numeric, then “cn + cd” could just as easily be returning a double representing the sum of the customer number and the LotusScript date-time variant’s numerical value.

Subject: RE: NotesLU view

The concatenation is working fine. And the code works fine when I create a Response document to a Document opened from a regular view. But the code fails when trying to do the same thing, with the same Document, but opened from an embedded view

Subject: RE: NotesLU view

Perhaps it is working (have you checked the value in debugger?), but it is far from “best practices”. In LotusScript, the string concatenator is “&”, not “+”, and relying on implicit type conversions will, sooner or later, cause mysterious problems to appear (usually at version upgrades). Cstr() and use the ampersand.

FWIW, I haven’t been able to reproduce your problem.

Subject: RE: NotesLU view

I wonder if there is something in the way that I have embedded the view that is causing the problem? < /Thinking out loud >

Subject: RE: NotesLU view

Hmmm… can’t see how the method could affect it unless the view formula is changed by your action and the object chain is broken, and I can’t see that happening with your code

Subject: RE: NotesLU view

Wayne, I’m tapped out! I’m certain I am not recreating your environment correctly. If I open a document contained in an embedded view, I can create the response doc using @formula language with no problems. Sorry I could not be more help.

Subject: Thanks for hanging in there with me…I will keep working on it

Subject: Creating Response Document for document opened from embedded view

Why don’t use just create a Response form that inherits CustomerNumber, Customer, and Contact from the main document and then use @Command([Compose];“responseformname”) in a button on the main form to open the response form?

Subject: RE: Creating Response Document for document opened from embedded view

Yes - and originally that was what I was doing. It was when I ancountered the problems mentioned above - it didn’t work when creating from a document that had been opened from an embedded view - that I began trying alternatives to get around the problem.