KTTKTT
asked on
Modify calendar invitiation entry button to also remove calendar entry on prompt
Need this button code modified to Remove the existing Lotus Notes Mail calendar entry that was previously added using same button. Thanks in advance.
' This is where you customize everything that can be customized about this button.
' The year, month and day of the event.
Const EVENT_YEAR = 2007
Const EVENT_MONTH = 3
Const EVENT_DAY = 9
' The time zone where the event is taking place.
' This is the number of hours you must subtract to get UTC.
' Sample values:
' USA: Eastern Time = -5, Eastern Time with Daylight Savings = -4.
' UK: GMT = 0, GMT with Daylight Savings = +1.
Const EVENT_TIME_ZONE = -5
' The start time of the event.
' These values are in 24 hour clock, also known as military time.
' 13 = 1pm = 13, 2pm = 14, 3pm = 15, 4pm = 16, 5pm = 17.
' These values are in the time zone specified above
Const EVENT_HOUR = 12
Const EVENT_MINUTE = 30
' The duration of the event in hours.
Const EVENT_DURATION = .5
' The description of the event.
Const EVENT_DESCRIPTION = "EVENT Teleconference"
' The Notes If the person hosting the event.
Const EVENT_HOST = "Fatumata Soukouna"
' The location where the event is taking place.
Const EVENT_LOCATION = "Teleconference: US Toll Free:800 XXX-XXXX / International Toll: 706 XXX-XXXX Passcode: XXXXXXX"
Const Event_body = "Presentation and Replay of this call will be available on the Tech Lib at: http://www.xxx.com"
' An icon to use for the event.
' Values are listed in the Domino Designer Help if you search for "icon column".
' Some good ones:
' 4 = a bunch of people
' 10 = a finger with string tied around it
' 11 = an "information" sign
' 15 = a loudspeaker broadcasting sound
' 23 = a newspaper
' 44 = a telephone
' 45 = a telephone off the hook
' 56 = nerdy glasses
' 67 = radio transmitter
' 70 = the earth
' 85 = smiley face
' 91 = bomb
' 97 = red diamond
' 139 = a video camera
' 148 = the sun shining
' 150 = a red exclamation mark
' 158 = hands shaking
' 163 = a man (spy?) in a red hat
' 166 = groucho glasses
' 173 = airplane flying
Const EVENT_ICON = 148
' All done.
------------
Sub Click(Source As Button)
' ############################################################################################
' Attention users:
' Configure this button via the (Declarations) section, accessed from the Objects tab that should be to the left of this text.
' ############################################################################################
' No user-servicable parts below this line.
' You may notice that the following code is tricky. It has to be, because of the following problems with the Notes APIs:
' 1) Textual dates and times are interpreted according to the user's local OS settings when the code runs.
' That means you can't use New NotesDateTime with a simple constant string to create a date and time field.
' 2) There's no way to set a NotesDateTime directly to a given time, other than to use a string. You have to go via a
' LotusScript date/time value.
' 3) LotusScript date/time values have no time zone associated with them, so you can't use them directly to create
' fields in a document.
' 4) You can only convert a LotusScript date/time to a NotesDateTime in the local time zone of the user, not in UTC.
' 5) @Zone and NotesInternational do not behave as documented. They are described as returning information about
' whether DST is in effect. In fact, they return whether DST will be in effect at any point during the year, so they're useless.
' Step 1. Work out what time zone the user will be in on the appointment date, including any DST offset.
' First, work out when noon is on the appointment date as a LotusScript date/time.
Dim noon As Variant
noon = Timenumber(EVENT_HOUR, EVENT_MINUTE, 0) + Datenumber(EVENT_YEAR, EVENT_MONTH, EVENT_DAY)
' Then create a NotesDateTime at that local date/time.
Dim startndt As New NotesDateTime("Now")
startndt.LSLocalTime = noon
Dim noongmt As Variant
' Now work out the corresponding GMT time as a LotusScript date/time.
noongmt = startndt.LSGMTTime
Dim tzoffset As Variant
' Subtract the two, multiply by 24 and round to 1 decimal place to get the user's time zone offset from GMT on the specified date.
tzoffset = Round(24 * (noon - noongmt), 1)
' Step 2. Work out a LotusScript date/time for the event.
' First work it out in GMT, using the time zone offset we were given.
Dim lsevent As Variant
lsevent = Timenumber(EVENT_HOUR, EVENT_MINUTE, 0) + Datenumber(EVENT_YEAR, EVENT_MONTH, EVENT_DAY)
lsevent = lsevent - (EVENT_TIME_ZONE / 24)
' Then convert to user's time zone on that date, as computed in step 1.
lsevent = lsevent + (tzoffset / 24)
' Step 3. Convert to a NotesDateTime
startndt.LSLocalTime = lsevent
' Do the same for the end date/time
Dim endndt As New NotesDateTime("Now")
endndt.LSLocalTime = lsevent + (EVENT_DURATION / 24)
' Step 4. Create the appointment document.
' Find user's mail database, open it, create a document.
' Dim session As New NotesSession
' Dim maildb As NotesDatabase
' Set maildb = session.CurrentDatabase
' previous lines commented for testing
Dim maildb As New NotesDatabase("", "")
Call maildb.OpenMail
Dim memo As NotesDocument
Set memo = maildb.CreateDocument
' Call function to write fields.
Call WriteAppointment(memo, startndt, endndt, EVENT_DESCRIPTION, EVENT_HOST, EVENT_LOCATION, EVENT_ICON)
Call memo.Save(True, False, False)
Messagebox "Appointment added March 9 12:30pm est."
End Sub
----------------
Sub WriteAppointment(doc As NotesDocument, ndtstart As NotesDateTime, ndtend As NotesDateTime, _
desc As String, host As String, locn As String, icn As Integer)
' Function to write essential fields to a document to create a calendar appointment
' Arguments are:
' NotesDocument to write to
' NotesDateTime start of event
' NotesDateTime end of event
' String description of event
' String name of host (e.g. John Doe/xxxxxxx/xxx)
' String location of event
' Integer icon to use in view
' Work out the host's name in canonical format
Dim nname As New NotesName(host)
' Write the document fields
doc.Form = "Appointment"
doc.Principal = nname.Canonical
doc.Chair = nname.Canonical
doc.AltChair = nname.Canonical
Call doc.ReplaceItemValue("StartDateTime", ndtstart)
Call doc.ReplaceItemValue("EndDateTime", ndtend)
Call doc.ReplaceItemValue("CalendarDateTime", ndtstart)
Call doc.ReplaceItemValue("_ViewIcon", icn)
doc.From = nname.Canonical
Call doc.ReplaceItemValue("StartTime", ndtstart)
doc.AppointmentType = "0"
doc.Subject = desc
doc.Location = locn
doc.Body = Event_Body
Call doc.ReplaceItemValue("EndDate", ndtend)
Call doc.ReplaceItemValue("EndTime", ndtend)
doc.Alarms = "1"
Call doc.replaceItemValue("$Alarm", 1)
Call doc.replaceItemValue("$AlarmDescription", desc)
Call doc.replaceItemValue("$AlarmOffset", -10)
Call doc.replaceItemValue("$AlarmUnit", "M")
Dim tmpitem As NotesItem
Set tmpitem = doc.replaceItemValue("ExcludeFromView", "D")
Call tmpitem.appendToTextList("S")
End Sub
Make the changes in the attached code snippet to find and remove the old version. To add a reminder to the current version, you would add the following above/below your cnote.Save:
cnote.ReplaceItemValue "$AlarmDescription", cnote.Subject
date1.adjustMinute -30
cnote.ReplaceItemValue "$AlarmTime", date1
cnote.ReplaceItemValue "$AlarmOffset", -30
cnote.ReplaceItemValue "$Alarm", 1
cnote.ReplaceItemValue "Alarms", "1"
cnote.save True, True '<- unchanged form your code
cnote.putInFolder "($Alarms)"
cnote.ReplaceItemValue "$AlarmDescription", cnote.Subject
date1.adjustMinute -30
cnote.ReplaceItemValue "$AlarmTime", date1
cnote.ReplaceItemValue "$AlarmOffset", -30
cnote.ReplaceItemValue "$Alarm", 1
cnote.ReplaceItemValue "Alarms", "1"
cnote.save True, True '<- unchanged form your code
cnote.putInFolder "($Alarms)"
Set date1 = New NotesDateTime("November 10 2007 01:00 PM ET")
Set date2 = New NotesDateTime("November 10 2007 02:00 PM ET")
Set oldStartTime = New NotesDateTime("November 9 2007 12:00 PM ET")
oldSubject = "Event...xyz" +Chr(10) + "Speaker: xyz" +Chr(10)+ "Location: Room xyz" +Chr(10)+ ""
'Message for the Details section of the calendar entry: (Use "+Chr(10)+" to add a line-break.)
cnote.Body = ""
' ** If you want to copy the entire body of the note you are sending into the details of the calendar then
' remove the single quote on the following 2 lines and add one at the beginning of the line above ***
'Set content = note.GetFirstItem("Body")
'Call content.CopyItemToDocument(cnote, "Body")
'************************ End of Calendar Change Section ***********************
Dim calendar as notesView, oldVersions as notesDocumentCollection, oldVersion as notesDocument
Set calendar = db.getView("($Calendar)")
Set oldVersions = calendar.getAllEntriesByKey(oldStartTime)
Set oldVersion = oldVersions.getFirstDocument
Do Until oldVersion Is Nothing
Set oldVersion = oldVersions.getNextDocument(oldVersion)
if oldVersion.Subject(0) = oldSubject Then oldVersion.remove True
Loop
cnote.From = note.From
ASKER
Thanks Qwaletee.
problem with type mismatch : getAllEntriesByKey
Removed Dim oldVersions as notesDocumentCollection
now receive error: INSTANCE getfirstdocument does not exist
Not sure why we set the oldStartTime to a different date ?
Set oldStartTime = New NotesDateTime("November 9 2007 12:00 PM ET")
problem with type mismatch : getAllEntriesByKey
Removed Dim oldVersions as notesDocumentCollection
now receive error: INSTANCE getfirstdocument does not exist
Not sure why we set the oldStartTime to a different date ?
Set oldStartTime = New NotesDateTime("November 9 2007 12:00 PM ET")
Oops!
Set oldVersions = calendar.getAllDocumentsBy Key(oldSta rtTime)
Set oldVersions = calendar.getAllDocumentsBy
oldStartTime is the date and time of the older version that you want deleted
ASKER
Thanks qwaletee. This is where I'm at with the code (see - getting object variable not set on the
"Set oldVersions = calendar.getAllDocumentsBy Key(oldSta rtTime)" line .
There also may be lines of code I don't need to Remove the calendar entry. Thanks again.
Sub Click(Source As Button)
' **Scroll down to the "CHANGE HERE" sections to customize this button.
Dim session As New NotesSession
Dim ws As New NotesUIWorkspace
Dim db As NotesDatabase
Dim content As NotesRichTextItem
Dim note As NotesDocument
Dim cnote As NotesDocument
Dim subject As String
Set uidoc = ws.CurrentDocument
Set note = uidoc.Document
Set db = note.parentdatabase
Set cnote = New NotesDocument (db)
'******CHANGE HERE - Change this section for calendar entry************
'**Message for subject (appears on calendar): (Use "+Chr(10)+" to add a line-break.)
Set date1 = New NotesDateTime("November 8 2007 02:00 PM ET")
Set date2 = New NotesDateTime("November 8 2007 04:30 PM ET")
Set oldStartTime = New NotesDateTime("November 8 2007 02:00 PM ET")
oldSubject = "xyz Demo" +Chr(10) + "Speaker: xyz person" +Chr(10)+ "Location: xyz Bldg." +Chr(10)+ ""
'Message for the Details section of the calendar entry: (Use "+Chr(10)+" to add a line-break.)
cnote.Body = ""
' ** If you want to copy the entire body of the note you are sending into the details of the calendar then
' remove the single quote on the following 2 lines and add one at the beginning of the line above ***
'Set content = note.GetFirstItem("Body")
'Call content.CopyItemToDocument (cnote, "Body")
'************************ End of Calendar Change Section ***********************
Dim calendar As notesView, oldVersions As notesDocumentCollection, oldVersion As notesDocument
Set calendar = db.getView("($Calendar)")
Set oldVersions = calendar.getAllDocumentsBy Key(oldSta rtTime)
Set oldVersion = oldVersions.getFirstDocume nt
Do Until oldVersion Is Nothing
Set oldVersion = oldVersions.getNextDocumen t(oldVersi on)
If oldVersion.Subject(0) = oldSubject Then oldVersion.remove True
Loop
cnote.From = note.From
cnote.Form = "Appointment"
cnote.AppointmentType = "0"
Call cnote.ReplaceItemValue("_V iewIcon", 159)
cnote.CHAIR = session.UserName
cnote.StartDateTime = date1.LSLocalTime
cnote.EndDateTime = date2.LSLocalTime
cnote.CalendarDateTime = date1.LSLocalTime
cnote.TimeRange = Timevalue(cnote.StartDateT ime(0)) & "-" & _
Timevalue(cnote.EndDateTim e(0))
cnote.ExcludefromView = "D"
cnote.BookFreetime = ""
Call cnote.AppendItemValue("$Bu syName", session.UserName)
Call cnote.AppendItemValue("$Bu syPriority ", "1")
Call cnote.AppendItemValue("$No Purge", dt2)
Call cnote.AppendItemValue("$Pu blicAccess ", "1")
cnote.save True, True
'******CHANGE HERE - Change this section for Calendar Entry Notification ************
Print "An entry for xyz session was removed from your calendar."
Msgbox "An entry for xyz session was removed from your calendar." ,MB_OK+MB_ICONINFORMATION, "Successfu l"
'************************ End of Calendar Entry Change Section ***********************
' ** Start of code for mail confirmation note. If you do not want a notification sent to you add a single quote
' at the beginning of the following 6 lines of code to comment out the section ***
Print "Sending confirmation note."
Dim maildoc As NotesDocument
Dim rtitem As NotesRichTextItem
Set maildoc = New NotesDocument(db)
maildoc.Form = "Memo"
Set rtitem = New NotesRichTextItem(maildoc, "Body")
'******CHANGE HERE - Change this section for Mail Reply Notification ************
maildoc.Subject = "I will no longer attend xyz session"
maildoc.SendTo = "xyz.com"
maildoc.CopyTo = ""
maildoc.BlindCopyTo = ""
Call rtitem.AppendText("I will no longer attend xyz session ")
maildoc.Body = "I will no longer attend xyz session."
'************************ End of Mail Reply Notification Change Section ***********************
Call maildoc.Send(False)
Print "Operation complete."
End Sub
"Set oldVersions = calendar.getAllDocumentsBy
There also may be lines of code I don't need to Remove the calendar entry. Thanks again.
Sub Click(Source As Button)
' **Scroll down to the "CHANGE HERE" sections to customize this button.
Dim session As New NotesSession
Dim ws As New NotesUIWorkspace
Dim db As NotesDatabase
Dim content As NotesRichTextItem
Dim note As NotesDocument
Dim cnote As NotesDocument
Dim subject As String
Set uidoc = ws.CurrentDocument
Set note = uidoc.Document
Set db = note.parentdatabase
Set cnote = New NotesDocument (db)
'******CHANGE HERE - Change this section for calendar entry************
'**Message for subject (appears on calendar): (Use "+Chr(10)+" to add a line-break.)
Set date1 = New NotesDateTime("November 8 2007 02:00 PM ET")
Set date2 = New NotesDateTime("November 8 2007 04:30 PM ET")
Set oldStartTime = New NotesDateTime("November 8 2007 02:00 PM ET")
oldSubject = "xyz Demo" +Chr(10) + "Speaker: xyz person" +Chr(10)+ "Location: xyz Bldg." +Chr(10)+ ""
'Message for the Details section of the calendar entry: (Use "+Chr(10)+" to add a line-break.)
cnote.Body = ""
' ** If you want to copy the entire body of the note you are sending into the details of the calendar then
' remove the single quote on the following 2 lines and add one at the beginning of the line above ***
'Set content = note.GetFirstItem("Body")
'Call content.CopyItemToDocument
'************************ End of Calendar Change Section ***********************
Dim calendar As notesView, oldVersions As notesDocumentCollection, oldVersion As notesDocument
Set calendar = db.getView("($Calendar)")
Set oldVersions = calendar.getAllDocumentsBy
Set oldVersion = oldVersions.getFirstDocume
Do Until oldVersion Is Nothing
Set oldVersion = oldVersions.getNextDocumen
If oldVersion.Subject(0) = oldSubject Then oldVersion.remove True
Loop
cnote.From = note.From
cnote.Form = "Appointment"
cnote.AppointmentType = "0"
Call cnote.ReplaceItemValue("_V
cnote.CHAIR = session.UserName
cnote.StartDateTime = date1.LSLocalTime
cnote.EndDateTime = date2.LSLocalTime
cnote.CalendarDateTime = date1.LSLocalTime
cnote.TimeRange = Timevalue(cnote.StartDateT
Timevalue(cnote.EndDateTim
cnote.ExcludefromView = "D"
cnote.BookFreetime = ""
Call cnote.AppendItemValue("$Bu
Call cnote.AppendItemValue("$Bu
Call cnote.AppendItemValue("$No
Call cnote.AppendItemValue("$Pu
cnote.save True, True
'******CHANGE HERE - Change this section for Calendar Entry Notification ************
Print "An entry for xyz session was removed from your calendar."
Msgbox "An entry for xyz session was removed from your calendar." ,MB_OK+MB_ICONINFORMATION,
'************************ End of Calendar Entry Change Section ***********************
' ** Start of code for mail confirmation note. If you do not want a notification sent to you add a single quote
' at the beginning of the following 6 lines of code to comment out the section ***
Print "Sending confirmation note."
Dim maildoc As NotesDocument
Dim rtitem As NotesRichTextItem
Set maildoc = New NotesDocument(db)
maildoc.Form = "Memo"
Set rtitem = New NotesRichTextItem(maildoc,
'******CHANGE HERE - Change this section for Mail Reply Notification ************
maildoc.Subject = "I will no longer attend xyz session"
maildoc.SendTo = "xyz.com"
maildoc.CopyTo = ""
maildoc.BlindCopyTo = ""
Call rtitem.AppendText("I will no longer attend xyz session ")
maildoc.Body = "I will no longer attend xyz session."
'************************ End of Mail Reply Notification Change Section ***********************
Call maildoc.Send(False)
Print "Operation complete."
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Bonus points: add a 30 minutue "notify" reminder to the existing entry if not removed. Thanks.
--------
Open in new window