Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Modify calendar invitiation entry button to also remove calendar entry on prompt

Posted on 2007-11-20
7
Medium Priority
?
1,054 Views
Last Modified: 2013-12-18
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

Open in new window

0
Comment
Question by:KTTKTT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 

Author Comment

by:KTTKTT
ID: 20321107
On 2nd thought this button code below is simpler to work with , please modifiy this one to remove existing entry with a prompt.
Bonus points:  add a 30 minutue "notify" reminder to the existing entry if not removed.  Thanks.
--------


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.)
	cnote.Subject = "Event...xyz" +Chr(10) + "Speaker: xyz"  +Chr(10)+ "Location: Room xyz" +Chr(10)+ ""
	'**date1 is the start date and time - date2 is the end date and time.  **
	Set date1 = New NotesDateTime("November 10 2007 01:00 PM ET")
	Set date2 = New NotesDateTime("November 10 2007 02:00 PM ET")
	'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 ***********************	
	cnote.From = note.From
	cnote.Form = "Appointment"
	cnote.AppointmentType = "0"
	Call cnote.ReplaceItemValue("_ViewIcon", 159)
	cnote.CHAIR = session.UserName     
	cnote.StartDateTime = date1.LSLocalTime
	cnote.EndDateTime = date2.LSLocalTime
	cnote.CalendarDateTime = date1.LSLocalTime
	cnote.TimeRange = Timevalue(cnote.StartDateTime(0)) & "-" & _
	Timevalue(cnote.EndDateTime(0))
	cnote.ExcludefromView = "D"
	cnote.BookFreetime = ""
	Call cnote.AppendItemValue("$BusyName", session.UserName)
	Call cnote.AppendItemValue("$BusyPriority", "1")
	Call cnote.AppendItemValue("$NoPurge", dt2)
	Call cnote.AppendItemValue("$PublicAccess", "1")
	
	cnote.save True, True 
	
	'******CHANGE HERE - Change this section for Calendar Entry Notification ************
	
	Print "An entry for Event xyz was successfully added to your calendar."
	Msgbox "An entry for Event xyz was succesfully added to your calendar." ,MB_OK+MB_ICONINFORMATION,"Successful"
	
	'************************ 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 attend xyz event"
	maildoc.SendTo = "xyz.com"
	maildoc.CopyTo = ""
	maildoc.BlindCopyTo = ""
	Call rtitem.AppendText("I will attend xyz event ")
	maildoc.Body = "I will attend the xyz   session."
	
	'************************ End of Mail Reply Notification Change Section ***********************	
	
	Call maildoc.Send(False)
	Print "Operation complete."
	
End Sub

Open in new window

0
 
LVL 31

Expert Comment

by:qwaletee
ID: 20322888
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)"
      


	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
	

Open in new window

0
 

Author Comment

by:KTTKTT
ID: 20323946
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")


0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 31

Expert Comment

by:qwaletee
ID: 20325638
Oops!

      Set oldVersions = calendar.getAllDocumentsByKey(oldStartTime)
0
 
LVL 31

Expert Comment

by:qwaletee
ID: 20325682
oldStartTime is the date and time of the older version that you want deleted
0
 

Author Comment

by:KTTKTT
ID: 20359907
Thanks qwaletee.  This is where I'm at with the code (see  - getting object variable not set on the
"Set oldVersions = calendar.getAllDocumentsByKey(oldStartTime)" 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.getAllDocumentsByKey(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
      cnote.Form = "Appointment"
      cnote.AppointmentType = "0"
      Call cnote.ReplaceItemValue("_ViewIcon", 159)
      cnote.CHAIR = session.UserName    
      cnote.StartDateTime = date1.LSLocalTime
      cnote.EndDateTime = date2.LSLocalTime
      cnote.CalendarDateTime = date1.LSLocalTime
      cnote.TimeRange = Timevalue(cnote.StartDateTime(0)) & "-" & _
      Timevalue(cnote.EndDateTime(0))
      cnote.ExcludefromView = "D"
      cnote.BookFreetime = ""
      Call cnote.AppendItemValue("$BusyName", session.UserName)
      Call cnote.AppendItemValue("$BusyPriority", "1")
      Call cnote.AppendItemValue("$NoPurge", dt2)
      Call cnote.AppendItemValue("$PublicAccess", "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,"Successful"
      
      '************************ 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
0
 
LVL 31

Accepted Solution

by:
qwaletee earned 2000 total points
ID: 20378484
Let's put in a couple of debug lines.  Where you now have:

  '************************ End of Calendar Change Section ***********************      
     
      Dim calendar As notesView, oldVersions As notesDocumentCollection, oldVersion As notesDocument
      Set calendar = db.getView("($Calendar)")
     
      Set oldVersions = calendar.getAllDocumentsByKey(oldStartTime)
   

Put in:
  '************************ End of Calendar Change Section ***********************      
     
      Dim calendar As notesView, oldVersions As notesDocumentCollection, oldVersion As notesDocument
      Set calendar = db.getView("($Calendar)")
      Msgbox "Test",,"Got the old time?"
      Msgbox "Yes - " & oldStartTime.LsLocalTime,,"Got the calendar?"
      Msgbox "Yes - " & calendar.Name,,"OK, should be no obj var not set prob"

      Set oldVersions = calendar.getAllDocumentsByKey(oldStartTime)
   


I have tried this very code myself with no problems.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
Problem "Can you help me recover my changes?  I double-clicked the attachment, made changes, and then hit Save before closing it.  But when I try to re-open it, my changes are missing!"    Solution This solution opens the Outlook Secure Temp Fold…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question