Reputation: 3300
I am running a Lotusscript Agent on "Before mail arrives". I need it to grab the text in the subject line after the "#" symbol. No matter how I try to get the Subject field (Evaluate, getFirstItem, getItemValue, etc), I always end up with an error. Usually it is a type mismatch or object variable not set.
The code below is my current code and returns an error 13 on line 14 "type mismatch"
Option Public
Option Declare
Sub Initialize
On Error GoTo ErrorHandler
Dim s As New NotesSession
Dim db As NotesDatabase
Dim view As NotesDocumentCollection
Dim doc As NotesDocument
Dim nextdoc As NotesDocument
Dim result As String
Set db = s.CurrentDatabase
Set view = db.Unprocesseddocuments
If Not view Is Nothing Then
Set doc = view.Getfirstdocument()
While Not doc Is Nothing
result = Evaluate ("@Right(Subject;""#"")", doc)
Print result
Set nextDoc = view.GetNextDocument(doc)
Call doc.Remove(True)
Set doc = nextDoc
Wend
End If
Print "End"
Done:
Exit Sub
ErrorHandler:
Select Case Err
Case Else
Print "Error " & CStr(Err) & " in agent on line " & CStr(Erl) & ": " & Error
Resume Done
End Select
End Sub
Upvotes: 1
Views: 1872
Reputation: 159
With reference to your original question about the Type Mismatch
when using Evaluate, please note the Designer help, under "Using the Evaluate statement":
"returnValue is an array in which the type and number of elements reflect the formula result; a scalar value is returned to element 0 of the array. You should use a variant for the return value, since you may not know how many elements are being returned."
Therefore, try the following changes:
...
Dim result As Variant
...
result = Evaluate (|@Right(Subject;"#")|, doc)
' Treat result as an array
Print result(0)
...
Upvotes: 3
Reputation: 1800
Before New Mail Arrives does not return NotesDocumentCollection. Use...
Sub Initialize
Dim Session As New NotesSession
Dim Doc As NotesDocument
Dim result As String
Set Doc = Session.DocumentContext
Let result = StrRight(Doc.Subject(0), "#")
End Sub
instead of UnprocessedDocuments...
Upvotes: 4