
 | 

The birthday reminder agent
Tip submitted by
Silvio Savaresi


Level: Intermediate
Works with: Notes/Domino
Updated: 07/01/2003

Related link:
More Tips from LDD | 
 | 
Do you usually forget friends' and colleagues' birthdays? With a simple agent, your Notes client can remind you of upcoming birthdays. This agent, placed in your Personal Address Book (PAB), can send you an email with the contact's name and a document link to his or her page in your PAB. The Birthday agent is a scheduled LotusScript agent that runs daily in your PAB to notify you of birthdays that occur the following day.
Here is the agent code. You can also download the code from the Sandbox.
Sub Initialize
'Summary : Code for sending mail to oneself about colleagues'/friends' birthdays
'This agent checks for tomorrow's birthdays and composes a mail message with a link and
'works automatically if the agent is enabled
'This agent works on the People view used in Notes
'You can create a Birthday view to display all colleagues'/friends' birthdays
'declaration
Dim Session As New NotesSession
Dim db As notesdatabase
Dim view As notesview
Dim doc,maildoc As notesdocument
Dim Tomorrow As notesdatetime
Dim item As notesitem
Dim Bday, BTday ,send ,text As String
Dim x,a As Integer
Dim user() As String
Dim userLink () As Variant
Set Tomorrow = New NotesDateTime( "Tomorrow" )
Set DB =Session.CurrentDataBase
Set View = DB.GetView("People")
Set Doc = View.GetFirstDocument
send="no"
x=0
' check in the view
While Not Doc Is Nothing
Set item = doc.GetFirstItem( "Birthday" )
Set Bday= item.DateTimeValue
If Bday Is Nothing Then
'nothing
Else ' if Birthday has been inserted ..
Redim Preserve user(x )
Redim Preserve userLink(x )
Bday = Day(Bday.dateonly) & Month(Bday.dateonly)
BTday = Day(Tomorrow.dateonly) & Month(Tomorrow.dateonly)
If Bday=BTday Then
'Compare dates to whether or not to send mail
send="yes"
user ( x)= doc.FirstName(0) + " " +doc.LastName(0)
Set userLink ( x)=doc
'assign link to the document
x=x+1
End If
End If
Set Doc = View.GetnextDocument(Doc)
Wend
If send = "yes" Then 'compose mail document
Set Maildoc = DB.CreateDocument
'rich text style setting
Dim richText As New NotesRichTextItem(maildoc, "Body")
Dim richStyle As NotesRichTextStyle
Set richStyle = session.CreateRichTextStyle
richStyle.NotesFont = FONT_HELV
richStyle.FontSize = 10
richStyle.NotesColor = COLOR_BLUE
Call richText.AppendStyle(richStyle)
' end rich text style setting
Maildoc.Form = "Memo"
Maildoc.Subject = "Birthday reminder! "
a=0
Call richText.AppendText("Tomorrow will be:")
Call richText.AddNewLine(1)
Forall z In user
If a<>x Then
Call richText.Addtab(3)
Call richText.AppendText(user(a) + "'s birthday. For details, follow the link ... " )
Call richText.AppendDocLink ( userLink(a) , user(a) )
Call richText.AddNewLine(2)
a=a+1
End If
End Forall
Maildoc.SendTo =session.CommonUserName
Call Maildoc.AppendItemValue( "_ViewIcon", 10 )
Call Maildoc.Send(False)
End If
Exit Sub
Err_Att:
Msgbox "Attention error : " & Str(Err) & ": " & Error$ & Chr(13)
Resume Next
End Sub
NOTE: The bold lines of code differ from the code provided in the Sandbox sample.
You can modify or enhance this agent and install it on a corporate Directory Catalog or on a common client address book.
SUBMIT YOUR TIPS! |
We encourage you to send us your tips (You can also click the "Would you like to submit a tip?" graphic below.) Your tips can be anything you've discovered about any Lotus product. The most important thing is that your tip be interesting, useful, or handy. And be sure to include complete information about how your tip works. For ideas, take a look at our tip archives. If we publish your tip, we'll send you the IBM Redbooks Lotus Collection on CD. |
|
| 
 |