I think I have everything written correctly except my IF condition and am confused because I’m dealing with dates and am having problems finding documentation but basically I want to do the following from an agent:
IF today’s date is greater than the EndDate field I want to send an email with a link informing them that the task is not completed and is past the enddate…
Dim session As New NotesSession Dim db As NotesDatabase
Dim v As NotesView
Dim doc As NotesDocument
Dim dc As NotesDocumentCollection
Dim parent As Notesdocument
Dim memo As Notesdocument
Dim SendToItem As Notesitem
Dim CopyToItem As Notesitem
Dim bodyitem As NotesRichtextItem
Set db = session.CurrentDatabase
Set v = db.GetView("Test")
Call v.refresh
Set doc = source.Document
Set memo =db.createdocument
Set bodyitem = New NotesRichTextItem(memo,"Body")
Set parent =db.getdocumentbyunid( doc.~$REF(0) )
Set dc = v.GetAllDocumentsByKey(doc.~$REF(0), True )
If dc .count =0 And parent.mailflag(0) <> 1 Then
memo.form ="Memo"
memo.SendTo =doc.CreatedBy(0)
memo.CopyTo ="Carl.Levin"
Memo.subject = "All tasks have been completed for project: " + doc.project(0)
parent.mailflag =1
Call bodyItem.AppendText("Please click on this link to view the Project document......" )
Call bodyItem.AppendDocLink(Parent,"")
Call parent.save(True,True)
Call memo.send(False)
End If
The If dc count needed to be changed as well as other lines but basically i wanted to get a doc collection and run thrugh all documents and find those that have end date that is less than date agent runs…I think I can figure out the rest of the code but was having trouble with IF statement as I’m not sure how to construct it
Here is some code that I have from an agent that we use to execute against the documents in the database.
This is all done in LotusScript, and sorry for pasting the whole this, but hopefully this will give you some ideas.
Thanks,
jean
Sub Initialize
%REM
changes:ReviewerNumber is 1 based so when Reviewer 1 is reviewing ReviewerNumber = 1.
Therefore, using a 0 based array, NextReviewer = ReviewerList(ReviewerNumber)
send the message
increment next reviewer if necessary
%END REM
'While this is similar to the same agent in doclib4, it is slightly different. The differences are commented
Set session = New NotesSession
Set db = session.CurrentDatabase
Set documents = db.Search("@Today => @Date(DueDateTime) & Status = 2", Nothing, 0)
If documents.Count = 0 Then Exit Sub
For d = 1 To documents.Count
Set note = documents.GetNthDocument(d)
ReviewWindow = note.ReviewWindow(0)
ReviewerList = note.ReviewerList
ReviewerNumber = note.ReviewerNumber(0)
Set dt = New NotesDateTime(note.DueDateTime(0))
Set nam = New NotesName(note.From(0))
'ReviewWindow in the Web version has values of 0 (no time limit), 1 (move to next reviewer), and 2 (send notification)
Select Case ReviewWindow
Case "1" 'Move to next reviewer
SendReminder("WindowExpired")
If ReviewerNumber + 1 <= Ubound(ReviewerList) Then
SendReminder("NotifyNextReviewer")
Else
SendReminder("NotifyOriginator")
note.Status = 3
End If
note.ReviewerNumber = ReviewerNumber + 1
Case "2" 'Send notification to current reviewer
SendReminder("Reminder")
End Select
If note.IsResponse Then note.RemoveItem("DueDateTime")
note.Save True, True, True
Next
Here is another example with the date and time format. This is using a document collection and is set to act on all the documents in the database that are unprocessed. Again, I am not sure about the End if’s that are all showing up, but I just copied this over and removed a bunch of other code.
Working with date and time can be tricky, so I hope this gives you an example you can try.
Jean
Sub Initialize
Dim s As New NotesSession
Dim db As NotesDatabase
Dim maildoc As NotesDocument
'Dim view As NotesView
Dim ndc As NotesDocumentCollection
Dim CurrentRequest As NotesDocument
Set db = s.CurrentDatabase
Set ndc = db.UnprocessedDocuments
Dim body As NotesRichTextItem
Dim currentDT As New NotesDateTime("")
Call currentDT.SetNow
Dim assigned_time As New NotesDateTime("")
Dim diff As Long
Dim request_date As String
Dim eo_number As String
Dim requestorName As String
Dim status_value As String
Dim mail1_name As String
Dim reminder_Sent As String
Set CurrentRequest = ndc.GetFirstDocument
While Not(CurrentRequest Is Nothing)
If CurrentRequest.form(0)= "Minutes" Then
requestorName = CurrentRequest.name_1(0)
requestorName = Trim$(requestorName)
If Len(requestorName) > 0 Then
status_value = currentrequest.status_1(0)
If status_value = "Open" Then
If CurrentRequest.HasItem("date_1") Then
Set assigned_time = currentrequest.getFirstItem("date_1").dateTimeValue
diff = currentDT.TimeDifference(assigned_time)
If diff > 0 Then
reminder_Sent = CurrentRequest.reminderSent(0)
If reminder_Sent = "No" Then
'Sends notice to first person in list
eo_number = currentrequest.eo_number(0)
request_date = currentrequest.Date_1(0)
mail1_name = CurrentRequest.newName1(0)
Set maildoc = New NotesDocument(db)
Set body = New NotesRichTextItem(maildoc, "Body")
maildoc.sendto=mail1_name
maildoc.form= "Memo"
maildoc.Principal = "EO Analysis"
maildoc.displaySent = "Notes Messenger"
maildoc.subject = "EO Analysis Request " + eo_number
Call body.appendtext("This is a reminder to complete the paperwork you recently received for this EO.")
Call body.appendtext("The EO Number is " + eo_number + ". ")
Call body.addnewline(2)
Call body.AppendDocLink(currentrequest,"")
'currentrequest.ReminderSent = "Yes"
Call maildoc.send(True)
currentRequest.ReminderSent1 = "Yes"
Else
End If
Else
End If
End If
End If
End If
End If
End If
End If
End If
End If
currentRequest.ReminderSent = "Yes"
Call currentRequest.save(True, True)
'Next
Set currentRequest = ndc.GetNextDocument(CurrentRequest)
Wend
When you were stating that you wanted to use a document collection, what about using a view and having a flag on the form so that if you have executed against the agent than the document would not appear in the view.
One thing to mention when using a view for such an agent, turn the auto update off on the view. And when it has ran through all of the documents, than turn the auto update back on.
be much simpler than it appears, anyway I’ve looked at your previous responses and just want to say thank you for responding…I’m thinking I need to do more research but i do appreciate your reposes
Let me take a look at this , looks like just what I need…You are a life saver…
Script seems so easy and straight forward not sure why I struggle with it, maybe I’m slow, stupid or just missing some basic fundamentals, not sure, but it takes me forever to solve problems using it…
With formula I understand the logic that I need but not so within script but believe it or not i love it, so powerful a language.
Anyway thanks again for your help this may just do the trick!!!
Dates in Lotuscript are a lot easier than the documentation would have you believe. They are stored as a floating-point number where the integer part is the date and the decimal part is the time of day.
So to make life easy first convert your document date to LS:
dim endDate as variant
endDate = cdat( doc.EndDate(0) )
then you can do simple maths tests:
if today > endDate then
call myNotificationEmailMethod()
end if
Other tests are just as easy. Say you want to send an escalated email 5 days after the end date:
if today > ( endDate + 5 ) then
call myEscalatedEmailMethod()
end if
You can also manipulate the date and save it back to the document. Say you want to extend the end date by a week:
You always need to take care with the time component. Depending on your application you might or might not want to take it into account. If you don’t want to use it just work with the integer part of the date-time value.
Also, if timezones are relevant, you may need to take their differences into account since the LS value will always be in GMT.