Domino Code Fragment

Code Name*
Scheduled agent that attaches file to documents.
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.18.117.216.229
Description*
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
The following script shows an example of a scheduled agent that attaches file to documents.

'Read Incoming Mail:

Option Public

' Default location for files, can be any directory accessable by the machine running this agent
Const ASCIIDir = "ascii"

Sub Initialize

Dim session As New Notessession
Dim db As Notesdatabase
Dim sendfile As String

Set db = session.Currentdatabase

' Look for any file in the default ASCII directory, dir$ returns one file at a time from the string given it
Dim pathName As String, fileName As String
pathName$ = ASCIIDir & "\*.*"
fileName = Dir$(pathName$, 0)

' Process all files in pathName$)
Do While fileName <> ""
sendfile = ASCIIDir & "\" & filename
Call ProcessFile(sendfile, session, db)
fileName = Dir$()
Loop
End Sub


Function ProcessFile (sendfile As String, session As Notessession, db As Notesdatabase) As Integer

' ready a notes memo, the body field is a richtext type.
Dim dbdoc As Notesdocument
Dim body As Notesrichtextitem
Set dbdoc = New NotesDocument( db )
dbdoc.Form = "Memo"

' open ascii file and read every line
fileNum% = Freefile()
Open sendfile For Input As fileNum%
Do While Not Eof(fileNum%)
' Read each line of the file.
Line Input #fileNum%, txt$
' Find delimiter position, I have chosen ":" as the delimiter
delpos = Instr (txt$ , ":" )
' The action "verb" is on the left and the text on the right of the delimiter
action = Ucase$(Trim$(Left$(txt$, delpos - 1)))
clause = Trim$(Mid$(txt$, delpos + 1, Len(txt$) - delpos))
' You could add any actions here you need.
Select Case action
Case "TO"
dbdoc.SendTo = clause
Case "CC"
dbdoc.CopyTo = clause
Case "BCC"
dbdoc.BlindCopyTo = clause
Case "SUBJECT"
dbdoc.Subject = clause
Case "BODY"
Set body = New NotesRichTextItem( dbdoc, "Body" )
Call body.AppendText(clause & Chr$(10))
Case "ATTACH"
Set body = New NotesRichTextItem( dbdoc, "Body")
Call Body.EmbedObject(EMBED_ATTACHMENT, "", clause)
Case Else
End Select
Loop
' Check for missing SendTo, you could log these errors to a text file, I'm just making them show up on the screen
If Not (dbdoc.HasItem("SendTo")) Then
Messagebox "No send to found for this text file",64,"No Send To Found"
Exit Function
End If
' Send document
dbdoc.PostedDate = Now
' This sets the field to save the message
dbdoc.SaveMessageOnSend = True
Call dbdoc.Send( False)
' Delete ASCII file
Close fileNum%
Kill (sendfile)
End Function