developerWorks  >  Lotus  >  Forums & community  >  Notes/Domino 4 and 5 Forum

Notes/Domino 4 and 5 Forum

developerWorks




Code Sample - adding a Calendar entry to user mail file
Doug Finner 08/26/2002 01:48 PM
Domino Designer -- Agents 4.6.5b Windows 95/98


Thought I'd post this up in case anyone could use it.

We have a db to store vacation, travel, or Leave of Absence listings for all users. It is likely that it will become the basis for a vacation planner, but that's in the future.
After a user has been granted or knows of time away, the adminstrative assistant for the appropriate work group typically enters the event into the shared day away planner.

I had a request to provide a mechanism for entries in this database to be used to populate one or more user calendars. Tyically, these mail file updates are targetted at either the person going away, or their manager.

The following code provides a function to copy selected calendar docs to 'my' calendar or 'other people's' calendars. If the 'other' option is selected, the user gets a dialog box with a Names and Address book drop down which is used to generate the list of mail files to be updated. I leave the exercise of building the dialog box to you.

Code below.

Hope this is of use to someone.

Doug

Agent called by View Action Button to start the sequence.

Sub Initialize
' version 3 of agent - this version detects if the user is adding their vacation/travel/leave of absence to their calendar (and adds it as an event) or if
' they are adding another person to their calendar (and adds it as a reminder).
' Additionally, this version offers the user an opportunity to add selected items to the calendar of others (ie secretary to boss).

Dim session As New NotesSession
Dim db As NotesDatabase
Dim collection As NotesDocumentCollection
Dim doc As NotesDocument
Dim DueDateStr As String
Dim DueDate As NotesDateTime
Dim EndDt As NotesDateTime
Dim Dur As Integer
Dim Subject As String
Dim PopUp As String
Dim PerName As String

Set db = session.CurrentDatabase
Set collection = db.UnprocessedDocuments
For i = 1 To collection.Count
Set doc = collection.GetNthDocument( i )
Subject = doc.Subject(0) & " " & doc.VacTrav(0)
PerName = doc.Subject(0)
EvtDueDate = doc.StartDate(0)
EvtEndDate = doc.EndDateTime(0)
Dur = doc.Duration(0)
Popup = doc.Subject(0) & " " & doc.VacTrav(0)
Set DueDate = New NotesDateTime(EvtDueDate)
Set EndDt = New NotesDateTime(EvtEndDate)
ToMine = Messagebox("Do you want to add the selected days to your calendar?", 36,"Add to your calendar?")
If ToMine = 6 Then
Call CreateReminder(DueDate, EndDt, Dur, PopUp, Subject, PerName, session)
End If
ToOthers = Messagebox("Do you want to add the selected days to other people's calendars?", 292,"Add to other calendars?")
If ToOthers = 6 Then
Call AddToOtherCals(DueDate,EndDt,Dur,PopUp,Subject,PerName,Session,doc)
End If
Next
Messagebox "Function is complete"
End Sub

Sub createReminder( dateTime As notesDateTime, EndDt As NotesDateTime, dur As Integer, popUpStr As String, subjectStr As String, PerName As String, sess As Variant )
' pass in start date time, end date time of the appointment, subject, popup string, name of user with appointment, and session. Appointment is set into requesting user's mail box.
' This defaults to 'all day'. Be interesting to see how it could be modified to be a timed appointment.

Dim userMailDb As New NotesDatabase( "", "" )
Call userMailDb.OpenMail
'If Person adding appointment to their calendar is the person with the appointment, appointment type = event, otherwise it's a reminder.
'get current user name
Dim UsrName As String
UsrName = sess.commonusername
'compare to appointment name and set appt type
Dim AppType As String
Dim ViewIco As Integer
If UsrName = PerName Then AppType = "2" Else AppType = "4" '2 = Event = appointment = multi day thing, 4 = 12 am reminder
If UsrName = PerName Then ViewIco = 160 Else ViewIco = 10 '160 for events, 10 for reminders.
If AppType = "2" Then ATStr = "Appointment" Else ATStr = "Reminder"

' loops to create reminder docs for each day, in cases where person with appt is not the person adding value to their calendar
For n = 0 To dur - 1
Dim reminderDoc As New NotesDocument( userMailDb )

' This routine sets a field called TimeRange in the apporintment. I'm not sure of the implication of this field - it doesn't appear to be used in reminders.
' This code snip was pulled from Notes.Net/LDD and was not part of the original alarm set macro.
If n = 0 Then Adjust = 0 Else adjust = 1
Call datetime.AdjustDay(Adjust,True)
Dim NTRange As NotesDateRange
Set NTRange = sess.CreateDateRange()
Set NTRange.StartDateTime = dateTime
Set NTRange.EndDateTime = EndDt
Set reminderdoc.TimeRange = NTRange
' end of TimeRange routine
Print "Adding: " & PerName & " " & ATStr & " for: " & dateTime.LocalTime

With reminderDoc
.ReplaceItemValue "$Alarm", 1
.ReplaceItemValue "$AlarmDescription", popUpStr
.ReplaceItemValue "$AlarmMemoOptions", ""
.ReplaceItemValue "$AlarmOffset", 0 'date time of event is likely to be 12 am so this parameter has no meaning here.
.ReplaceItemValue "$AlarmUnit", "M"
.ReplaceItemValue "_viewIcon", ViewIco
.Form = "Appointment"
.Subject = subjectStr
.Alarms = "1"
.Duration = dur
.ExcludeFromView = "D" ' keeps items out of the draft view.
.CalendarDateTime = dateTime.lsLocalTime
.StartDate = dateTime.lsLocaltime
.StartTime = dateTime.lsLocaltime
.StartDateTime = dateTime.lsLocaltime
.EndDate = EndDt.lsLocaltime
.EndTime = EndDt.lsLocaltime
.EndDateTime = EndDt.lsLocaltime
.AppointmentType = AppType

.ComputeWithForm False, False
.Save True, False
.PutInFolder( "$Alarms" )
End With
If AppType = "2" Then Exit Sub
Next
'*********************************************************************************************************************************************************************************************************
Messagebox "Appointment added to the your calendar"
End Sub

Sub AddToOtherCals( dateTime As notesDateTime, EndDt As NotesDateTime, dur As Integer, popUpStr As String, subjectStr As String, PerName As String, sess As Variant ,doc As NotesDocument)
On Error Goto ErrorTrap

' pass in start date time, end date time of the appointment, subject, popup string, name of user with appointment, and session. Appointment is set into requesting user's mail box.
' This defaults to 'all day'. Be interesting to see how it could be modified to be a timed appointment.
Dim ws As New NotesUIWorkspace
flag = ws.DialogBox( "dlgAddToList" , True ,True , , , , , "who ya wanna tell?", doc ) 'adds two new fields to the vacation doc, AddName and MailFileNames.
If Not flag Then Exit Sub 'if user cancels, code aborted

'If Person adding appointment to their calendar is the person with the appointment, appointment type = event, otherwise it's a reminder.
'get current user name
Dim UsrName As String
UsrName = sess.commonusername
'compare to appointment name and set appt type
Dim AppType As String
Dim ViewIco As Integer
If UsrName = PerName Then AppType = "2" Else AppType = "4" '2 = Event = appointment = multi day thing, 4 = 12 am reminder
If UsrName = PerName Then ViewIco = 160 Else ViewIco = 10 '160 for events, 10 for reminders.
If AppType = "2" Then ATStr = "Appointment" Else ATStr = "Reminder"

' loops to create reminder docs for each day, in cases where person with appt is not the person adding value to their calendar
MFName = doc.MailFileNames
Forall MF In MFName
FileName$ = MF
server = "Notes/Kollsman"
Dim OtherMailDb As New NotesDatabase( "", "" )
Call OtherMailDb.Open( Server, MF )
For n = 0 To dur - 1
Dim reminderDoc As New NotesDocument( OtherMailDb )

' This routine sets a field called TimeRange in the apporintment. I'm not sure of the implication of this field - it doesn't appear to be used in reminders.
' This code snip was pulled from Notes.Net/LDD and was not part of the original alarm set macro.
If n = 0 Then Adjust = 0 Else adjust = 1
Call datetime.AdjustDay(Adjust,True)
Dim NTRange As NotesDateRange
Set NTRange = sess.CreateDateRange()
Set NTRange.StartDateTime = dateTime
Set NTRange.EndDateTime = EndDt
Set reminderdoc.TimeRange = NTRange
' end of TimeRange routine
Print "Adding: " & PerName & " " & ATStr & " for: " & dateTime.LocalTime & " to: " & mf

With reminderDoc
.ReplaceItemValue "$Alarm", 1
.ReplaceItemValue "$AlarmDescription", popUpStr
.ReplaceItemValue "$AlarmMemoOptions", ""
.ReplaceItemValue "$AlarmOffset", 0 'date time of event is likely to be 12 am so this parameter has no meaning here.
.ReplaceItemValue "$AlarmUnit", "M"
.ReplaceItemValue "_viewIcon", ViewIco
.Form = "Appointment"
.Subject = subjectStr
.Alarms = "1"
.Duration = dur
.ExcludeFromView = "D" ' keeps items out of the draft view.
.CalendarDateTime = dateTime.lsLocalTime
.StartDate = dateTime.lsLocaltime
.StartTime = dateTime.lsLocaltime
.StartDateTime = dateTime.lsLocaltime
.EndDate = EndDt.lsLocaltime
.EndTime = EndDt.lsLocaltime
.EndDateTime = EndDt.lsLocaltime
.AppointmentType = AppType

.ComputeWithForm False, False
.Save True, False
.PutInFolder( "$Alarms" )
End With
If AppType = "2" Then Exit Sub
Next
'*********************************************************************************************************************************************************************************************************
GetNextMailFile:
End Forall
'*********************************************************************************************************************************************************************************************************
Messagebox "Appointment added to the specified calendars"
Exit Sub
'*********************************************************************************************************************************************************************************************************
ErrorTrap:
Messagebox "There was a problem updating mail file: " & FileName$ & ". The process will continue with the next selected user"
Resume GetNextMailFile
'*********************************************************************************************************************************************************************************************************
End Sub

Go back