A request that recently came to me was to put a reminder for an upcoming IT outage on the calendar for a specific list of users. To me, this seemed like a natural extension of the Company Communications Database. The form I used for setting up the reminder was just a modified mass email form that was already built. All the user has to do is select who gets the reminder, select when the reminder should go off, and enter the subject and body of the reminder. Below is the subroutine that actually puts the reminders on the user's calendar:
Sub SendReminder(person As NotesDocument, doc As NotesDocument)
Dim mailfile As NotesDatabase
Dim collection As NotesDocumentCollection
Dim reminder As NotesDocument
Dim item As NotesItem
Dim body As NotesRichTextItem
Dim oldbody As NotesRichTextItem
Dim datetime As NotesDateTime
Set mailfile = New NotesDatabase(person.MailServer(0),person.MailFile(0))
If Not(mailfile.IsOpen) Then Exit Sub
Set datetime = New NotesDateTime(doc.GetItemValue("calendardatetime")(0))
Set collection = mailfile.Search(|Form = "Appointment" & ApptUNID = "| & doc.UniversalID & |"|,Nothing,0)
If collection.Count = 0 Then
Set reminder = mailfile.CreateDocument()
reminder.Form = "Appointment"
Set item = reminder.ReplaceItemValue("$Alarm",1)
Set item = reminder.ReplaceItemValue("$AlarmOffset",0)
' Set item = reminder.ReplaceItemValue("$NoPurge",doc.GetItemValue("calendardatetime"))
Set item = reminder.ReplaceItemValue("$PublicAccess","1")
Set item = reminder.ReplaceItemValue("$CSVersion","2")
Set item = reminder.ReplaceItemValue("_ViewIcon",10)
Set item = reminder.ReplaceItemValue("Alarms","1")
Set item = reminder.ReplaceItemValue("AppointmentType","4")
Set item = reminder.ReplaceItemValue("ApptUNID",doc.UniversalID)
Set item = reminder.ReplaceItemValue("Categories","Company Reminders")
Set item = reminder.ReplaceItemValue("Chair","CN=Generic ID/O=Company")
Set item = reminder.ReplaceItemValue("ExcludeFromView","D")
Call item.AppendToTextList("S")
Set item = reminder.ReplaceItemValue("OrgTable","C0")
Set item = reminder.ReplaceItemValue("Principal","CN=Clark Construction/O=Clark")
Set item = reminder.ReplaceItemValue("SequenceNum",1)
Set item = reminder.ReplaceItemValue("UpdateSeq",1)
Set item = reminder.ReplaceItemValue("WebDateTimeInit","1")
Else
Set reminder = collection.GetFirstDocument
Set item = reminder.ReplaceItemValue("SequenceNum",reminder.SequenceNum(0) + 1)
Set item = reminder.ReplaceItemValue("UpdateSeq",reminder.UpdateSeq(0) + 1)
Call reminder.RemoveItem("Body")
End If
Set item = reminder.ReplaceItemValue("CalendarDateTime",doc.GetItemValue("calendardatetime")(0))
Set item = reminder.ReplaceItemValue("EndDate",Datevalue(datetime.DateOnly))
Set item = reminder.ReplaceItemValue("EndDateTime",doc.GetItemValue("calendardatetime")(0))
Set item = reminder.ReplaceItemValue("EndTime",Timevalue(datetime.TimeOnly))
Set item = reminder.ReplaceItemValue("StartDate",Datevalue(datetime.DateOnly))
Set item = reminder.ReplaceItemValue("StartDateTime",doc.GetItemValue("calendardatetime")(0))
Set item = reminder.ReplaceItemValue("StartTime",Timevalue(datetime.TimeOnly))
Set item = reminder.ReplaceItemValue("Subject",doc.subject(0))
Set oldbody = doc.GetFirstItem("Body")
Set body = reminder.CreateRichTextItem("Body")
Call body.AppendRTItem(oldbody)
Call reminder.ComputeWithForm(True,False)
Call reminder.Save(True,False,True)
End Sub
A couple of things that you should notice about the subroutine. First, a couple of NotesDocument objects are passed in, one pointing to the user's person document in the address book and the other pointing to the reminder document. Second, the agent is built to be able to update reminders that have already been created. The ApptUNID field will contain the UniversalID of the reminder document so that if the reminder document gets updated, the reminder on the user's calendar will also be updated, not duplicated. Finally, I only set the static calendar fields when the document is created. I think that I got all the required fields, but I might have missed one. Please drop me a line if you think I did.
Created 9/20/2005 3:15:55 PM email | website
I had to create a method for users to register for training/events from our Intranet. Here is what I had to end up using. I'm probably using too many fields, though...
Sub AddCalendarItem(doc As NotesDocument)
Dim db As Notesdatabase
Dim session As New NotesSession
Dim item As NotesItem
Dim startdttm As NotesDateTime
Dim enddttm As NotesDateTime
Dim window As NotesDateRange
Dim names As String
Dim dur As Integer
Dim username As String
Set db = New NotesDatabase("SERVER",doc.MailFile(0))
Dim cEntry As New NotesDocument(db)
Dim rtitem As Variant
Dim itemIcon As NotesItem
'----------- Set User and Description ----------------
cEntry.Form = "Appointment"
cEntry.From = doc.CreationUser(0)
cEntry.Principal = doc.CreationUser(0)
cEntry.Chair = doc.CreationUser(0)
cEntry.~$BusyName = doc.CreationUser(0)
cEntry.~$BusyPriority = "1"
cEntry.Subject = doc.Title
Set rtitem = doc.GetFirstItem("Body")
Call rtitem.CopyItemToDocument(cEntry, "Body")
cEntry.AppointmentType = "0"
'----------- Set Date and Times ----------------
Set startdttm = New NotesDateTime(doc.StartDate(0) & " " & doc.StartTime(0))
Set enddttm = New NotesDateTime(doc.StartDate(0) & " " & doc.EndTime(0))
cEntry.StartDateTime = startdttm.LSLocalTime
cEntry.StartDate = startdttm.LSLocalTime
cEntry.StartDate_2 = startdttm.LSLocalTime
cEntry.EndDateTime = enddttm.LSLocalTime
cEntry.EndDate = enddttm.LSLocalTime
cEntry.EndDate_2 = enddttm.LSLocalTime
cEntry.StartTime = startdttm.LSLocalTime
cEntry.StartTime_2 = startdttm.LSLocalTime
cEntry.tmpStartTime_local = startdttm.LSLocalTime
cEntry.EndTime = enddttm.LSLocalTime
cEntry.EndTime_2 = enddttm.LSLocalTime
cEntry.DispDur_2 = doc.dspDuration
cEntry.DispDur_1 = doc.dspDuration
cEntry.DispDuration_1 = doc.dspDuration
cEntry.calendarDateTime = startdttm.LSLocalTime
cEntry.StartTimeZone = "Z=5$DO=1$DL=4 1 1 10 -1 1$ZX=25$ZN=Eastern"
cEntry.EndTimeZone = "Z=5$DO=1$DL=4 1 1 10 -1 1$ZX=25$ZN=Eastern"
'----------- Set Other Fields ----------------
cEntry.~$NoPurge = enddttm.LSLocalTime
cEntry.tmpWasMailed = "1"
cEntry.MailOptions=""
cEntry.ExcludeFromView = "D; S"
cEntry.OrgTable = "C0"
cEntry.Location = doc.EvtLocation
Set itemIcon = New NotesItem(cEntry, "_ViewIcon", 160)
itemIcon.IsSummary = True
cEntry.Logo = "stdNotesLtr0"
cEntry.OrgState = "x"
cEntry.Repeats = ""
cEntry.Resources = ""
cEntry.SaveOptions = ""
cEntry.SequenceNum = "1"
Call cEntry.save(True, True)
End Sub
Created 10/18/2005 4:54:51 AM email | website
Hi Sean,
I've been looking for something like this to add leave requested to a persons calendar using the OpenNTF Leave Requests database but being a pretty poor programmer I'm not sure how I can adpt your code for the job. Could you give me an idea of what field I need on my form and where the subroutine should be placed.
Thanks,
Gary
Created 10/27/2005 8:37:45 AM email | website
Gary-
Your form can be as simple or complex as you want it to be. Basically, all you need is the date or date and time of the calendar entry and the person that needs to have it added to their calendar. Any other information, like subject of the calendar entry or body, are completely optional. You could almost copy and paste the code in this entry into an agent and it would work like you wanted. If you would like me to do the code for you, let me know and I will see how much work it would take to add it to the template.
Sean---
Created 3/18/2009 5:04:46 AM email |
hi
i have a severe problem for calender meeting
i need to reschedule the meeting after it was sent, when i do this ,it is working but as creating new instance from old meeting and let the original meeting as it is
if you can tell me how to remove the old meeting, this will be great
Also note that the meeting was sent to another user not for me
Thank you
M.J
your help is really highly appreciated