Search code examples
lotus-noteslotusscriptnotesview

Getting "The linked document (UNID... cannot be found in the view (UNID ...)" Error Message


I'm getting the error message below: enter image description here

Upon clicking the doclink which was being attached in the e-mail which was generated by me through clicking the send to managers button. I also tried using NotesURL instead of doclink:

Call rtitem.appendtext(emaildoc.Notesurl)

but the generated URL is different from the doclink. Below is the generated from the doclink itself.

Generated NotesURL: notes://LNCDC@PHGDC/__48257E3E00234910.nsf/0/237B2549EEA393A948257E530042BA4A?OpenDocument

Doclink: Notes://LNCDC/48257E3E00234910/28BD6697AB48F55348257E2D0006CF60/C9B0266FDC0D929E48257E530041D6F9

Can you please help? Below is my agent code.

%REM
	Agent Send Email to Managers
%END REM
Option Public
Option Declare
Dim s As NotesSession
Dim db As NotesDatabase
Dim emaildoc As NotesDocument
Dim paydoc As NotesDocument
Dim rtitem As NotesRichTextItem
Dim i As Integer
Dim view As NotesView
Sub Initialize
	Set s = New NotesSession
	Set db = s.CurrentDatabase
	Set view = db.GetView("Pending Claims")
	Dim addresses As NotesName
	Dim arrpem As Variant
	ReDim arrpem(0)
	Set paydoc = view.GetFirstDocument

	'// Store all PEM names in an array
	While Not(paydoc Is Nothing)
		ReDim Preserve arrpem(UBound(arrpem) + 1)
		arrpem(UBound(arrpem)) = paydoc.PeopleManager(0)
		Set paydoc = view.GetNextDocument(paydoc)

	Wend
	'// Remove all duplicate PEM names and empty entries in the array
	arrpem = FullTrim(ArrayUnique (arrpem))

	'// Loop the PEM names array
	ForAll pem In arrpem
		Set emaildoc = New NotesDocument(db)
		Set addresses = New NotesName(pem)
		If addresses.abbreviated <> "" Then
			emaildoc.SendTo = addresses.abbreviated
			emaildoc.Subject = "Leave Balances of your Direct Reports"
			emaildoc.Form = "Memo"
			Set rtitem = New NotesRichTextItem(emaildoc, "Body")
			Call rtitem.AppendText("Dear " & addresses.common & ",")
			Call rtitem.AddNewLine(2)

			'// Remove paydoc value which was used in the PEM names array
			Set paydoc = Nothing

			'// Get all documents that has matching PEM name in the view
			Dim dc As NotesDocumentCollection
			Set dc = view.GetAllDocumentsByKey(addresses.Abbreviated, True)
			Set paydoc = dc.GetFirstDocument

			'// Append doc link of employee
			While Not(paydoc Is Nothing)
				Call rtitem.AppendText("Doc link of :" & paydoc.FMName(0) & " " & paydoc.LastName(0))
				Call rtitem.appenddoclink(emaildoc, "Link to Leave Balance of " & paydoc.FMName(0) & " " & paydoc.LastName(0))			
				Call rtitem.AddNewLine(1)
				Set paydoc = dc.GetNextDocument(paydoc)
			Wend

			'// Send email per PEM
			Call emaildoc.Send(False)
		End If
	End ForAll

	MsgBox "Emails successfully sent."

End Sub 


Solution

  • The doclink is pointing back to the document you've created in memory for your email. When sent, that document no longer exists in the original database.

    Change your code to be:

    Call rtitem.appendtext(paydoc.Notesurl)