How do you add a response's doclink to a parent document?

I want to place a doc link of a response doc to a parent document and I found these instructions:

Sub PlaceDocLinkInParent (rdoc As NotesDocument)

REM “NOTE” rdoc is supposed to be the response document that you want the

REM Doc Link for. As I said above, I will assume you have obtained this and

REM just need to call this procedure to place the doc link.

Dim sess As New NotesSession

Dim db As NotesDatabase

Dim pdoc As NotesDocument

Dim m_unid As String

Dim rt As NotesRichTextItem

Set db = sess.CurrentDatabase

m_unid$ = rdoc.ParentDocumentUNID

Set pdoc = db.GetDocumentByUNID(m_unid$)

Set rt = New NotesRichTextItem(pdoc, “DocLinkField”)

Call rt.AppendDocLink(rdoc, “Link To Reponse Document”)

Call pdoc.Save(True, False)

End Sub

I’m truly novice with LotusScript and I cannot get this work, can someone help and give me detail advice how to proceed?

Thanks!

Subject: How do you add a response’s doclink to a parent document?

(1) Do you have a default view in your database?

(2) Does your parent document have a field called DocLinkField of type RichText?

(3) Do you have Author access to the parent document?

(4) How are you running the code?

Subject: RE: How do you add a response’s doclink to a parent document?

Thanks for quick reaction!

Answers to your questions:

  1. Yes

  2. Yes

  3. Yes

  4. I have tried:

a. run this code through button which starts agent

b. add this code to form’s QuerySave option

Do I have to call this function somehow…? Sorry, but I don’t understand LotusScript structure.

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.

Subject: RE: How do you add a response’s doclink to a parent document?

Thanks for advice!

Now I tested with agent which only runs when response doc is saved and it only runs once (when it’s new doc), but I get error message: “Variant does not contain an object”. Response doc opens, but this function does not work, link is not added to parent doc.

Yes, empedded view element it’s good idea and I actually tried that yesterday, but there’s one problem. This db is “work order” database

and every work order can include multiple plans, (also there’s hundreds of work orders). Empedded view element is truly great and useful if

it could only show those plans which are attached for open work order.

Isn’t this first option ok, if I prevent parent doc from multiple editing, because people are only able to make new plans (response docs) from work order (parent doc)? If I add this script to PostOpen event:

Sub Postopen(Source As Notesuidocument)

If Not source.isnewdoc And source.editmode Then

	i = Messagebox(EditNotAllowed$,16,message$)

	source.editmode=False

End If

End Sub

Subject: RE: How do you add a response’s doclink to a parent document?

Explain what you want to do instead of how you’re trying to do it. The doclink idea is a bad one (and I really don’t think you “get” the embedded view idea, either – particularly the single category option).

Subject: RE: How do you add a response’s doclink to a parent document?

Hi,

Sorry, if my messages has been unclear. I want users to be able easily access response docs from a parent doc. This is a main point, hopefully there’s some way to solve this.

Subject: RE: How do you add a response’s doclink to a parent document?

And the embedded view of responses is the best way to do that. Do it EXACTLY as I described it – categorize the responses view on the formula value @Text($Ref) and use the formula @Text(@DocumentUniqueID) in the “Show single category” object of the embedded view.

Subject: RE: How do you add a response’s doclink to a parent document?

Thank you, thank you, thank you!!!

This was the solution I was looking for! How easy things are when you know what to do…! It’s good that there’s experts like you, I learned a lot. I’m sorry that I didn’t read previous advices carefully, this case could have been solved hours ago…