Hi,
I have an agent that scans mail to retrieve information from certain type of mail then update a form on the database from a different server. It works fine if it executes from an action button but for “Before/After mail arrives” or On Schedule - Daily, the code is dead when it get a handle of a view of a database on another server. I know that since I add some debug code by sending myself a mail . Here is my code :
Sub Initialize
Set session = New NotesSession
Set db = session.CurrentDatabase
Set doc =session.DocumentContext
Subject = doc.Subject(0)
formName = doc.Form(0)
'Starting code to search for alerts
Fromtemp = "Store"
FromSender = doc.From(0)
SearchforString1X223 = "DeCa Alert: StoreGazer"
SearchforString2X223 = "posted a X223 at"
'****************************************************
'****Make sure the sender start with "Store"
positionOfFrom = Instr(FromSender$, Fromtemp$)
positionOfString1X223 = Instr(Subject$ , SearchforString1X223$ )
positionOfString2X223 = Instr(Subject$ , SearchforString2X223$ )
'***End Code for alerts****************
If (positionOfString1X223 <>0) And (positionOfString2X223 <> 0) And (positionOfFrom<>0) And formName = "Memo" Then
Call ProcessX223Alert
End If
End Sub
Sub ProcessX223Alert
'Get X223 Datetime and StoreID
On Error Goto Somethingwrong
Call GetX223Info
Set dbDeCA = New NotesDatabase( "US-FAIRDEV001/Dev/US", "16TA\\DeCA_TLog.nsf" )
keys(1) = X223DateOnly 'Search for date first - Data get from Sub GetX223Info
keys(2) = StoreID 'then search for StoreID - Data get from Sub GetX223Info
Set ByKeyView = dbDeCA.GetView( "GetDocByKey" ) ''<------------------- Code dead after this line.
'******************* test to see where the problem is *****************
'Set memoform = New NotesDocument(db)
'memoform.form = "Memo"
'memoform.SendTo = "Hung Tran/Houston"
'memoform.subject = "Before New Mail:Sub ProcessX223Alert before GetView"
'Call memoform.Send(False,False)
'******************* End test *******************************************
Set TLogDoc = ByKeyView.GetDocumentByKey(keys)
If Not (TLogDoc Is Nothing) Then
TLogDoc.X223Date = X223Date
Call TLogDoc.Save(True,False)
End If
Exit Sub
Somethingwrong:
Msgbox "Something wrong on ProcessX223Alert"
End Sub
If I place test code lines that send mail to myself before the : Set ByKeyView = dbDeCA.GetView( “GetDocByKey” ) then I receive mails but nothing is executed after that line. If I place those test codes after the GetView line then no mail get sent! So obviously, Lotus Notes scheduled agent does not like a handle to a view from a different database + different server.
What do I need to do? Please help. Many thanks in advance.