I have an agent that is supposed to upload PDF files and someone (Matt) was helpful and suggested additional code but I am still not getting any files uploading in the “PDFFileAttachment” RT field. Previous to that the result was that some icon was appearing next to the field with the filename (not what I wanted).
One thing I noticed is that the TheAttachment variable is not getting any values passed to it (do I have too many parameters in it?):
Set TheAttachment = rtitem.EmbedObject(EMBED_ATTACHMENT,“”, pdfFilePath, pdfFile)
My apologies if this reposting may be breaking some of the rules here - the thread was getting a bit long. My LS skills are limited and would appreciate any assistance to let me know where this is going wrong.
Dan
Option Public
Option Declare
Sub Initialize
Dim session As New Notessession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim profiledoc As NotesDocument
Dim rtfBody As NotesRichTextItem
Dim v As NotesView
Dim TheAttachment As NotesEmbeddedObject
Dim rtitem As Variant
Dim pdfDirectory As String
Dim pdfPartial As String
Dim pdfFile As String
Dim pdfFileName As String
Dim pdfFilePath As String
Set db = session.CurrentDatabase
'Initialize agent log activity recording
Dim agentLog As New NotesLog( "Agent Log" )
Call agentLog.OpenNotesLog( "", "agentlog.nsf" )
’ LOG: number of documents to be processed
agentLog.LogAction("Number of documents processed: " & db.UnprocessedDocuments.Count)
'get the “(Database Configuration)” Profile document based on the current user and get items from it
Set profiledoc = db.GetProfileDocument("(Database Configuration)")
pdfDirectory = profiledoc.CSVFolder(0)
Set v = db.getview("vImportedCSVRecords")
Set doc = v.GetFirstDocument
'Cycle through the vImportedCSVRecords view, and starting with the first document go through the contents
Do While Not( doc Is Nothing )
' LOG: nth document
agentLog.LogAction("Processed document - Policy #: " & doc.Policy(0))
'Get a handle on the last four digits of the attachment file we are looking for by getting the value of the field called FourDig
pdfPartial = Trim$(doc.FourDig(0))
pdfFileName = FindPDFFile( pdfPartial, pdfDirectory )
If pdfFileName <> "" Then
pdfFile = pdfPartial
Forall i In doc.Items
If i.Name = "PDFFileAttachment" Then
If Not Isempty(i.EmbeddedObjects) Then
Forall o In i.EmbeddedObjects
If rtItem.Type = RICHTEXT Then
pdfFilePath = pdfDirectory & pdfFileName
Set TheAttachment = rtitem.EmbedObject(EMBED_ATTACHMENT,"", pdfFilePath, pdfFile)
End If
End Forall
End If
End If
End Forall
Call doc.Save( True, True )
End If
Set doc = v.GetNextDocument(doc)
Loop
End Sub
Function FindPDFFile( fileNumber As String, pdfDirectory As String ) As String
Dim pdfDirFile As String
FindPDFFile = ""
pdfDirFile$ = Dir$( pdfDirectory & "*.pdf", 0 )
Do While pdfDirFile <> ""
If pdfDirFile$ Like ("*" & fileNumber$ & ".pdf") Or pdfDirFile$ Like ("*" & fileNumber$ & ".PDF")Then
FindPDFFile = pdfDirFile$
Exit Function
End If
pdfDirFile = Dir$()
Loop
End Function