Subject: RE: How do you add a response’s doclink to a parent document?
Yes, you do have to call the function somehow. In any LotusScript event, you will find a built-in subroutine called Initialize or Click – that is the only code that’s going to happen by default. Buttons and hotspots will run Click, events and agents will run Initialize.
In this case, you will probably want to run the code from the response form’s PostSave event. (No, you probably won’t actually want to do this at all, but we’ll get to that after the LotusScript lesson.) When you go to the PostSave event, you will be in the Initialize event by default, and should see this:
Sub Initialize(Source As Notesuidocument)
End Sub
You’ll want to put your cursor right at the end of the End Sub line and hit Enter, then paste the code you have now on the next line – it will become its own module. Go back to the Initialize subroutine and edit it to look like this:
Sub Initialize(Source as Notesuidocument)
Call PlaceDocLinkInParent(Source.Document)
End Sub
{EDIT
I should add here that the actual code required to make this work in a reasonable way is more complicated. You would need to ensure that the doclink is only added when the document is initially created, but since $Ref is not available until the document has been saved at least once, you would need to keep variables available to tell you whether the document is new or not (IsNewDoc and IsNewNote are both false after the save, so you’d need your own “was new doc” flag variable, and you’d need to keep track of whether the PostSave code has been run yet, whether the doclink was created successfully or not, yada, yada headache…).
}
Now, there is a problem with this kind of strategy. There’s no good way to manage multiple responses. The user may not have permission to write to the parent document. Even if you do the writing with an agent that’s allowed to write to any document, the parent may be open somewhere for editing. It is much better to create a view of response documents (de-select “Show response documents in a hierarchy”) categorized on @Text($Ref) and embed the view on the parent form using the single category formula @Text(@DocumentUniqueID). You still get “links” (users can click to open responses), but you also get labelling so the user can tell the response documents apart without having to open them, you don’t get duplicates, and so on.