Link to home
Start Free TrialLog in
Avatar of Glactus
Glactus

asked on

Wrong Email Notification is going from agent

There's is an email notification which works on notification date set.
There are two fields notifiy date and due date.
Email should go if the current date is between notifiy date and due date

user created an action on 18/02/2011.
The Due Date is set as 10/03/2011.
The Notification Date is set as 25/02/2011 and the Delay Notice is set as "weekly" so user would expect to receive the first notification on 25/02/2011.

User started receiving the notification today 19/02/2011 (the next day the action has been created)

Please find the below code for mail sending :

Set duedate=New NotesDateTime(doc.Getitemvalue("act_DueDate")(0))
Set notifydate=New NotesDateTime(doc.Getitemvalue("act_Notify")(0))
stat=doc.Getitemvalue("act_status")(0)
resp=doc.getItemValue("act_responsible")
copy=doc.getItemValue("act_ccPeople")
bodystr="delay notice 1"      
bodystr1="delay notice2"            
      If (stat="") Then
      
        If (currentdate.Dateonly() >=notifydate.Dateonly())And (currentdate.Dateonly() <=duedate.Dateonly())Then
           ' Call mailsend(doc,db,resp,copy,bodystr)
       End If
      If (currentdate.Dateonly()> duedate.Dateonly())Then
          'Call mailsend(doc,db,resp,copy,bodystr1)
      End If
Avatar of mbonaci
mbonaci
Flag of Croatia image

You can use the code from this recent, similar post:

https://www.experts-exchange.com/questions/26801021/Send-Reminder-Agent.html
So, to check whether the date falls between two dates:

Can you post the actual code, since both MailSend calls are commented out.
'if Notification date is older (smaller) than Our date
'and Our date is older (smaller) than Due date

Dim dueDate As New NotesDateTime(doc.Getitemvalue("act_DueDate")(0))
Dim notifyDate As New NotesDateTime(doc.Getitemvalue("act_Notify")(0))
Dim currentDate As New NotesDateTime(Today)

If notifyDate.TimeDifference(currentDate) > 0 And currentDate.TimeDifference(dueDate) > 0 Then
    '... send mail...
End If

Open in new window

Sorry, wrong code:
'if Today is bigger than Notification date (notification date passed)
'and Today is smaller than Due date (Due date still has to come)

Dim dueDate As New NotesDateTime(doc.Getitemvalue("act_DueDate")(0))
Dim notifyDate As New NotesDateTime(doc.Getitemvalue("act_Notify")(0))
Dim currentDate As New NotesDateTime(Today)

If currentDate.TimeDifference(notifyDate) > 0 And currentDate.TimeDifference(dueDate) < 0 Then
    '... send mail...
End If

Open in new window

It sounds little odd that you don't want to send mail if both Notification and Due date have passed?
I mean, shouldn't you have to check only doc state and Notification date, and if state is empty and Notification date has passed - send mail?
Avatar of Glactus
Glactus

ASKER

 If (currentdate.Dateonly()> duedate.Dateonly())Then
          'Call mailsend(doc,db,resp,copy,bodystr1)

this is sending mail if the current date is greater then duedate .
The mail body is different in this case.

The code i have mentoned in the above post is working fine from 1 year .
Its giving problem for one particular document .

I have copied that particular document in the test copy of the database.
I debuged the agent and its working fine .

But in production server its giving trouble.

Can you please tell me why it is behaving like this .?
Avatar of Sjef Bosman
1. I'd code this differently:

      If currentdate.Dateonly()> duedate.Dateonly() Then
          'Call mailsend(doc,db,resp,copy,bodystr1)
      ElseIf currentdate.Dateonly() >=notifydate.Dateonly() Then
           ' Call mailsend(doc,db,resp,copy,bodystr)
      End If

2. Are your dates Strings? Is "10/2/2011" converted to February 10th or October 2nd ? Can you run your code in the debugger?
Have you examined the date fields on that document?
Go to document properties > second tab > select date field > does it say the type is Time/Date in the right window?

Have you tried to simply open that document, save and close it, to refresh items with actual form fields?
Avatar of Glactus

ASKER

@sjef_bosman

both duedate and notifydate are notesdate time .
Can you answer my questions?
Avatar of Glactus

ASKER

Yes mbonaci

Now the user is telling that he is getting this issue for all the documents .

I did what you suggested but the problem is still there .

both duedate and notifydate are notesdate time

As i have debugged the agent and  the agent is working fine for me.There are no issues in the test enviornment.

but it is giving trouble in production server.

One silly question, since test environment is working fine, have you checked the production server date?
You haven't posted the actual code.
Post the entire agent's code.
The server's date string conversion may differ from the user's. Usually, servers display American date/time strings. Maybe that's where your problem lies...
Avatar of Glactus

ASKER

Use "SendReminderMail"

Sub Initialize()
  On Error GoTo ErrorHandler
      Dim ns As New NotesSession
      Dim db As NotesDatabase
      Dim View As NotesView
      Dim doc As NotesDocument
      Dim vcReq As NotesViewEntryCollection
      Dim entry As NotesViewEntry
      Dim docMail As NotesDocument
      Dim returnVar As Variant
      Dim SendTo,CopyTo As Variant
      Dim Subject As String
      Dim rbody As String
      Dim duedate As NotesDateTime
      Dim notifydate As NotesDateTime
      Dim currentdate As New NotesDateTime(now)
      Dim stat As String
      Dim resp,copy As variant
      Set db             =       ns.CurrentDatabase
      Set View       =       db.GetView("Notification")
      Dim bodystr As string
      Dim bodystr1 As String
      Set doc =view.Getfirstdocument()
      
      
      While Not doc Is Nothing
      Set duedate=New NotesDateTime(doc.Getitemvalue("act_DueDate")(0))
      Set notifydate=New NotesDateTime(doc.Getitemvalue("act_Notify")(0))
      stat=doc.Getitemvalue("act_status")(0)
      resp=doc.getItemValue("act_responsible")
      copy=doc.getItemValue("act_ccPeople")
      bodystr=" body1111"      
      
    bodystr1="body 2222"      
      If (stat="") Then
      
        If (currentdate.Dateonly() >=notifydate.Dateonly())And (currentdate.Dateonly() <=duedate.Dateonly())Then
            Call mailsend(doc,db,resp,copy,bodystr)
       End If
      If (currentdate.Dateonly()> duedate.Dateonly())Then
          Call mailsend(doc,db,resp,copy,bodystr1)
      End If
      
      End If
            Set doc=view.Getnextdocument(Doc)
            
            Wend
      Exit Sub
      
      ErrorHandler:      
      MessageBox CStr(Err)+"-" +Error(Err) + " at line " + CStr(Erl)
      Exit Sub
      
      End Sub
Avatar of Glactus

ASKER

@all

i have debugged again nd found the logic is wrong .

I set due date to 10march2011

If (currentdate.Dateonly()> duedate.Dateonly())Then
          Call mailsend(doc,db,resp,copy,bodystr1)
  End If

it is satisfying the above condition thats wy it is sending mails.

But of course: DateOnly is a String.

Try with

If currentdate.LSLocalTime> duedate.LSLocalTime Then
          Call mailsend(doc,db,resp,copy,bodystr1)
End If
I posted the correct logic in my previous question, here: #34942264
ASKER CERTIFIED SOLUTION
Avatar of mbonaci
mbonaci
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial