[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 998
  • Last Modified:

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
0
Glactus
Asked:
Glactus
  • 9
  • 5
  • 3
1 Solution
 
mbonaciCommented:
You can use the code from this recent, similar post:

http://www.experts-exchange.com/Q_26801021.html
0
 
mbonaciCommented:
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

0
 
mbonaciCommented:
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

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mbonaciCommented:
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?
0
 
GlactusAuthor Commented:
 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 .?
0
 
Sjef BosmanGroupware ConsultantCommented:
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?
0
 
mbonaciCommented:
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?
0
 
GlactusAuthor Commented:
@sjef_bosman

both duedate and notifydate are notesdate time .
0
 
mbonaciCommented:
Can you answer my questions?
0
 
GlactusAuthor Commented:
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.

0
 
mbonaciCommented:
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.
0
 
Sjef BosmanGroupware ConsultantCommented:
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...
0
 
GlactusAuthor Commented:
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
0
 
GlactusAuthor Commented:
@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.

0
 
Sjef BosmanGroupware ConsultantCommented:
But of course: DateOnly is a String.

Try with

If currentdate.LSLocalTime> duedate.LSLocalTime Then
          Call mailsend(doc,db,resp,copy,bodystr1)
End If
0
 
mbonaciCommented:
I posted the correct logic in my previous question, here: #34942264
0
 
mbonaciCommented:
I meant to say, my previous post, here.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 9
  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now