문제

I have form with 3 fields adress,status,ReportingDate.

Adress field contains the ID where the mil has to be sent.

Now I have created an agent where it should mail to the data present in adress field when status is incomplete and reporting date is exactly 7 days before todays date.

My Code:

Option Public
Option Declare

Sub Initialize
Dim sess As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim timestamp As New NotesDateTime("Today")
Dim Noresponsedate As NotesDateTime
Dim vw As NotesView
Dim diff As Integer
Dim SendTo As Variant

Call timestamp.SetNow()
Set db = sess.CurrentDatabase

Set vw = db.GetView( "data" )   
Set doc = vw.GetFirstDocument()
While Not doc Is Nothing    
If doc.Status(0) = "Incomplete" Then    
Call checktimedifference(doc)   
End if  
    Set doc = vw.GetNextDocument(doc)
  wend
End Sub

Sub checktimedifference(doc As NotesDocument)
Dim due As NotesDateTime
Dim present As NotesDateTime
Dim timecheck As variant
Set due = New NotesDateTime ( "" )
Set present = New NotesDateTime ( "Today" )
timecheck = doc.ReportingDate(0)
due.LSLocalTime = timecheck
If due.TimeDifference (present) = -604800 Then   
Call sendmailtouser(doc)     
End If  
End Sub
Sub sendmailtouser(doc As NotesDocument)
Dim db As NotesDatabase
Dim rtiitem As NotesRichTextItem
   Dim maildoc As NotesDocument
    dim recepient As variant    
  Set maildoc = New NotesDocument( db )
  Set rtiitem = New NotesRichTextItem( maildoc, "Body" )    
  recepient = doc.adress(0) 
  maildoc.from = db.Title
  maildoc.form = "memo"
  maildoc.subject = "A Minor Injury Report:" & doc.Seq_No(0) & " needs your response"
  maildoc.SendTo = recepient
   Call rtiitem.AppendText( "Please respond to this Minor Injury Report" )
  Call rtiitem.AddNewline( 2 )
   Call rtiitem.AppendText( "Your response for the Minor Injury Report: " &  doc.Seq_No(0) & " is required" )
   Call rtiitem.AddNewline( 2 )
   Call rtiitem.AppendText( "Please click on the following link to access the document.")
      Call rtiitem.AppendDocLink( doc, db.Title )   
     Call maildoc.Send(False)   
    End Sub

When I am running the agent on client I am getting the following error:

enter image description here

Please help me to solve the error and send mail to the recepients.

도움이 되었습니까?

해결책

Not using any error handling is very bad practice. But your error will most probably happen in the sendmailtouser- sub, where you dim a local notesdatabase- object named db without actually initializing it.

The line

set maildoc = New NotesDocument( db ) 

will fail. Either declare db globally and set it in your initialize or dim ses in that sub again and set db again (worst case as you have to do it for every document)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top