This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal


Jan 14, 2016, 11:43 AM
7 Posts

Attach Documents fails

  • Category: Domino Designer
  • Platform: Windows
  • Release: 9.0.1
  • Role: Developer
  • Tags: EMBED_ATTACHMENT,Error 4067,attachments
  • Replies: 1

I have a scheduled agent that runs to pick up files stored on the network and copy them to a response document. This code has successfully run for well over a year until a few days ago.

Now it's stopped working and I'm getting the following error in the logs:

14/01/2016 09:47:45 AMgr: Agent ('Attach Documents' in 'Instruction\NemPROv2.nsf') message box: Found the file named \\ncifs2\ncifiles2\pls\Import Documents\3282517.pdf.
14/01/2016 09:47:45 AMgr: Agent ('Attach Documents' in 'Instruction\NemPROv2.nsf') message box: Attach Documents Error number Is 4067 at line 71.

Line 71 is this:

Call rtItem.EmbedObject( EMBED_ATTACHMENT, "", fileName)

Error 4067 is NOTES_ERR_ATTACH_FAILED but I can find no reason why it has failed. The document has been found and it works perfect in the DEV environment. It did work perfectly in the live environment too until recently.

The agent is set to Allow Restricted Operations and the folder has the proper access rights to allow the server to connect to it.

I thought that there might be some corruption on the database so I ran compact, fixup, and updall. They didn't fix the problem.

Full code below:

%REM
Attach Documents
Created Oct 16, 2014 by Jason Horton/
Description: 
Find the first unprocessed instruction. 
Access the file system. 
Get the documents previously imported from the FTP site.
The file name should match the client acNo.
Create an frmReportRecord form. Populate it and make it a response to the instruction.
Move the document into a "Processed" folder
Get the next document
%END REM
Option Public
Option Declare

Const DIR_NOT_FOUND = 76
Sub Initialize
'Get the folder name from keywords
On Error GoTo ErrorReturn

Dim keywordview As NotesView
Dim keyworddoc As NotesDocument
Dim keyword As String
Dim folderName As String
Dim crntDb As NotesDatabase
Dim s As New NotesSession
Print "**********ATTACH DOCUMENTS STARTED**********"
Set crntDb = s.CurrentDatabase
keyword = "import folder"
Set keywordview = crntDb.GetView( "LookupKeywords" )
Set keyworddoc = keywordview.GetDocumentByKey( keyword, True )
If Not keyworddoc Is Nothing Then
folderName = keyworddoc.KeywordList(0)
End If
If folderName = "" Then GoTo ErrorNoFolder
Dim DirResult As String
Dim file As string
Dim filename As String
Dim newFilename As String
Dim vw As NotesView
Dim doc As NotesDocument
Dim attachDoc As NotesDocument
Dim rtItem As NotesRichTextItem
Dim object As NotesEmbeddedObject

'Open the view of unprocessed instructions
Set vw = crntDb.GetView("lookupawaitingdocuments")
'Get the first document
Set doc = vw.GetFirstDocument
Do While Not doc Is Nothing
'Read the account number
file = doc.acNo(0)
file = ReplaceSubstring( file, "\", "_")
file = ReplaceSubstring( file, "/", "_")
file = ReplaceSubstring( file, ".", "_")
filename = folderName & "\" & file & ".pdf"
newFilename = folderName & "\Processed\" & file & ".pdf"
If doc.processedAttachments(0) <> "Yes" Then
On Error DIR_NOT_FOUND Resume Next
DirResult = Dir$ (filename, 0)
On Error GoTo ErrorReturn
If DirResult <> "" Then
MsgBox "Found the file named " + filename + ".", 0 + 64, "Found"
'Attach the document
Set attachDoc = crntDb.CreateDocument
'Populate all the fields
attachDoc.Form = "frmReportRecord"
attachDoc.cliRef = doc.cliRef(0)
attachDoc.instruction_id = doc.instruction_id(0)
attachDoc.agName = doc.agName(0)
attachDoc.userName = doc.userName(0)
attachDoc.administrator = doc.administrator(0)
attachDoc.manager = doc.manager(0)
attachDoc.type = doc.type(0)
attachDoc.reportType = doc.reportType(0)
attachDoc.referenceNo = doc.referenceNo(0)
attachDoc.cliName = doc.cliName
attachDoc.acNo1 = doc.acNo(0)
attachDoc.subAddress1 = doc.subAddress1(0)
attachDoc.subAddress2 = doc.subAddress2(0)
attachDoc.subTown = doc.subTown(0)
attachDoc.subPostcode = doc.subPostcode(0)
attachDoc.DocType = "Documents for Service"
attachDoc.access = doc.access(0)
attachDoc.statusHistory = Format(Today(), "Medium Date") & ": Added by System."
Set rtItem = New NotesRichTextItem( attachDoc, "Body" )
Call rtItem.EmbedObject( EMBED_ATTACHMENT, "", fileName)
Call attachDoc.ComputeWithForm(True, False)
'Make it a response to 'doc'
Call attachDoc.MakeResponse(doc)
Call attachDoc.Save(True, False)
'Add a marker to show it has been attached.
doc.attachments = Format(Today, "dd/mm/yyyy") + ": Document for Service uploaded (System)"
'Move it to the Processed folder
FileCopy fileName, newFilename
Kill fileName
Else
MsgBox "Could not find the file named " + filename + ".", 0 + 64, "Not Found"
End If
End If
'Get the next document
Call doc.save(False, False)
TryNext:
Set doc = vw.GetNextDocument(doc)
Loop

Print "**********ATTACH DOCUMENTS COMPLETED**********"
Exit Sub

ErrorNoFolder:
MsgBox "Attach Documents. There is no folder specified."
Resume ErrorReturn2
ErrorReturn:
MsgBox "Attach Documents Error number Is " + CStr(Err) + " at line " + CStr(Erl) + ".", 0 + 16, "Error"
If CStr(Err) = "4067" Then 
Resume TryNext 
Else 
Resume ErrorReturn2
End if
ErrorReturn2:
Exit Sub
End Sub
Function ReplaceSubstring( sourceStr As String, findStr As String, replaceStr As String) As String
Dim replaceLen As Integer
Dim nextFound As Integer
Dim startPos As Integer

replaceLen = Len(replaceStr)
startPos = 1
nextFound = InStr( sourceStr, findStr)
If nextFound = 0 Then
'source string does not contain find string so nothing to do - return source String As Is
ReplaceSubstring = sourceStr
Exit Function
End If

While Not nextFound = 0
' Replace all occurrances of find string with replace string
ReplaceSubstring = ReplaceSubstring + Mid$( sourceStr, startPos, nextFound-startPos) + replaceStr
startPos = nextFound + replaceLen
nextFound = InStr( startPos, sourceStr, findStr)
Wend
If startPos < Len( sourceStr) Then
' don't forget the stuff at the end of source string
ReplaceSubstring = ReplaceSubstring + Right$( sourceStr, Len(sourceStr) - startPos + 1)
End If
End Function

Any help on tracking down the cause would be appreciated. I'm baffled.

Jan 19, 2016, 10:24 AM
7 Posts
Additional information

To give further feedback on this. I have used exactly the same code for a view action and it works perfectly for the same documents that aren't being picked up by the agent.


This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal