We help IT Professionals succeed at work.

Lotus Notes Calendar Entry Add, Remove, Modify Buttons

KTTKTT
KTTKTT asked
on
7,356 Views
Last Modified: 2013-12-18
I use one Calendar button to add a new calendar entry.
I use a second modify button to modify existing calendar entry that was previously added.  The remove portion looks for the old start time, then finds the old subject line, then deletes the entry.
Problem 1: The modify button successfully adds a Re-schedule, but does not Remove the old entry if the subject line has a carriage return.  A work around is to only enter the 1st line of the subject to be removed, but I also need it to find the entire subject line with the carriage return if a carriage return exists.
Problem 2:  When using the work around to only find the 1st subject line to remove, the calendar entry only Removes if the New Subject Line is different from the Old Subject line - not sure why this would be a problem since the new rescheduled entry is for a different date and time.
See Code Snippet.  Please be very descriptive and detailed in your answer.  Thanks
Add Calendar Entry Button:  Works fine:
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 Removedit As String
	Set uidoc = ws.CurrentDocument
	Set note = uidoc.Document
	Set db = note.parentdatabase    
	Set cnote  =  New NotesDocument (db)    
	
'*********CHANGE HERE - Change start date for new calendar entry - Change this section for calendar entry************		
	
	Set date1 = New NotesDateTime("August 10 2008 9:00 AM ET")
	
'*********CHANGE HERE - Change end date for new calendar entry  - Change this section for calendar entry************		
	
	Set date2 = New NotesDateTime("August 10 2008 10:30 AM ET")                     
	
'*********CHANGE HERE - subject for  new calendar entry - Change this section for calendar entry************
'*********To add a line break , use "+Chr(10)+" .  
'*********For example: newSubject = "xyz Demo" +Chr(10) + "Speaker: xyz person"  +Chr(10)+ "Location: xyz Bldg." +Chr(10)+ ""	
	
'*********CHANGE HERE - description  for  new calendar entry - Change this section for calendar entry************
	
	newSubject = "Business Meeting" +Chr(10) + "Remote Call-in Number below: "  +Chr(10)+ ""	
	
'*********CHANGE HERE - description  for  new calendar entry - Change this section for calendar entry************
	cnote.Body = "Remote Call-in information: " +Chr(10) + "Toll free:  1-877-000-0000" +Chr(10) + " " +Chr(10) + "" +Chr(10) + "Participant Passcode:  300000" +Chr(10)+ "Presentation URL:   http://www.ibm.com" +Chr(10) + "   " +Chr(10)+""
	
	'cnote.Body = ""	
	
'*********CHANGE HERE - To add additional descriptive text from your memo to the new calendar entry description - Change this section for calendar entry************	
'*********Follow the next 2 steps:
'*********Step 1:  
'*********Uncomment the two lines of code below by removing the single quote preceding the lines of code so that the line of code become black text: 
'*********For example: 
'*********  'Set content = note.GetFirstItem("Body") 
'*********  'Call content.CopyItemToDocument(cnote, "Body") 
'*********Step 2:	
'*********Comment the line above by adding a single quote before the following line of code so the line of code becomes green text. 
'*********For example:	
'*********cnote.Body = ""	
	
	'Set content = note.GetFirstItem("Body")
	'Call content.CopyItemToDocument(cnote, "Body")
	
	
'**************************** End of Calendar Change Section ***********************	
	
	
'***********(1) *********  Begin Do Not Change Below***********************************************************************************
	
	'Create calendar entry 
	
	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 = ""
	cnote.Subject=newSubject 'displays in calendar entry and when alarm is generated
	Call cnote.AppendItemValue("$BusyName", session.UserName)
	Call cnote.AppendItemValue("$BusyPriority", "1")
	Call cnote.AppendItemValue("$NoPurge", dt2)
	Call cnote.AppendItemValue("$PublicAccess", "1")
	
	Print "An entry for " & newSubject & " has been successfully added to your calendar."
	Msgbox "An entry for " & newSubject & " was succesfully added to your calendar." ,MB_OK+MB_ICONINFORMATION,"Successful"
	
	date1.adjustMinute -30
	cnote.ReplaceItemValue "$AlarmTime", date1
	cnote.ReplaceItemValue "$AlarmOffset", -30
	cnote.ReplaceItemValue "$Alarm", 1
	cnote.ReplaceItemValue "Alarms", "1"
	cnote.save True, True 
	cnote.putInFolder "($Alarms)"
	Print "Calendar entry added."
	
	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")     
	
'***********(1) ****************  End Do Not Change Above***********************************************************************************
	
	
'*********CHANGE HERE - Change Subject for the confirmation note ***********			
	maildoc.Subject = "I will call in for the Business Meeting"	
'*********CHANGE HERE - Change Send To  for the confirmation note ***********	
'********To send the confirmation note to one person, just update the name 
'	maildoc.SendTo = "zzz@us.ibm.com"
	
'********To send the confirmation note to multiple people, do the following:    
'*********Comment the code  above by adding a single quote before the line of code so the line of code becomes green text.
'*********For example:	
'*********'maildoc.SendTo = "zzz@us.ibm.com"
'*********Then uncomment the following lines of code below by removing the single quote preceding the lines of code so that the line of code become black text:  
'*********Note:  the X in the SendToList (1 to X) must match the number of recipients 
'*********For example:  
'*********Dim SendToList(1 To 2) As String
'*********SendToList(1) = "Lotus Notes ID here for 1st sendto"
'*********'SendToList(2) = "Lotus Notes ID here for 2nd sendto"
'*********Call maildoc.ReplaceItemValue("SendTo",SendToList)
	
	
'	Dim SendToList(1 To 3) As String
'	SendToList(1) = "Lotus Notes ID here for 1st sendto"
'	SendToList(2) = "Lotus Notes ID here for 2nd sendto"
'	SendToList(3) = "Lotus Notes ID here for 2rd sendto" 
'	Call maildoc.ReplaceItemValue("SendTo",SendToList)
	
	
'*********CHANGE HERE - Change CC for the confirmation note ***********
	maildoc.CopyTo = ""
	
'*********CHANGE HERE - Change BCC for the confirmation note ***********
	maildoc.BlindCopyTo = ""
	
'*********CHANGE HERE - Change Body for the confirmation note ***********
	Call rtitem.AppendText("I will call in for the meeting")
	
'*********CHANGE HERE - To disable sending the confirmation note add a quote before the following line  so that the text becomes green
'	Call maildoc.Send(False)
	
'************************ End of Mail Reply Notification Change Section ***********************	
	Print "Operation complete."
	
End Sub
 
-----------------------------------------------------------------------
Modify Calendar Entry Button:  Needs Improvement to find and handle multi-line Subject and to not have to modify new Subject line to be different from the original subject line if the date/time is different.
 
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
	Set uidoc = ws.CurrentDocument
	Set note = uidoc.Document
	Set db = note.parentdatabase    
	Set cnote  =  New NotesDocument (db) 
	Dim Removedit As String
	
'**************************** Start of Calendar Change Section ***********************		
	
'*********CHANGE HERE - Change the start time for the new calendar entry ************
	
	Set date1 = New NotesDateTime("August 11 2008 9:00 AM ET") 
	
'*********CHANGE HERE - Change the end time for the new calendar entry ************
	
	Set date2 = New NotesDateTime("August 11 2008 10:30 AM ET") 
	
'*********CHANGE HERE - Change the start time for calendar entry to remove ************
	
	Set oldStartTime = New NotesDateTime("August 10 2008 9:00 AM ET") 
	
'*********CHANGE HERE - Change the subject for the calendar entry to remove************
'*********Note:  oldSubject is the key to remove the calendar entry.  This text must be an exact match  for the removal  to work.  
'*********To add a line break , use "+Chr(10)+" .  
'*********For example: oldSubject = "xyz Demo" +Chr(10) + "Speaker: xyz person"  +Chr(10)+ "Location: xyz Bldg." +Chr(10)+ ""	
	
	' oldSubject = "Business Meeting" +Chr(10) + "Remote Call-in Number below: "  +Chr(10)+ ""	     ' this doesn't work
	' works and finds old subject when I remove carriage return:      oldSubject = "Business Meeting"       'but need it to find the carriage return and find the 2nd subject line
	oldSubject = "Business Meeting"
	
'*********CHANGE HERE - subject for  new calendar entry - Change this section for calendar entry************
'*********To add a line break , use "+Chr(10)+" .  
'*********For example: newSubject = "xyz Demo" +Chr(10) + "Speaker: xyz person"  +Chr(10)+ "Location: xyz Bldg." +Chr(10)+ ""	
	
	' newSubject = "Business Meeting" +Chr(10) + "Remote Call-in Number below: "  +Chr(10)+ ""	' to add new subject to rescheduled event, may need to use the same subject line as the original
	'Worked only when I changed the new subject line text - added "Rescheduled"    'newSubject = "Rescheduled Business Meeting" +Chr(10) + "Remote Call-in Number below: "  +Chr(10)+ ""	
	newSubject = "Rescheduled Business Meeting" +Chr(10) + "Remote Call-in Number below: "  +Chr(10)+ ""	
	
'*********CHANGE HERE - decscription field for new calendar entry description  - Change this section for calendar entry************	
	
	cnote.Body = "Remote Call-in information and presentation location: " +Chr(10) + "Toll free:  1-800-000-0000" +Chr(10) + " " +Chr(10) + "" +Chr(10) + "Participant Passcode:  300000" +Chr(10)+ "Presentation URL:   http://www.ibm.com" +Chr(10) + "   " +Chr(10)+""
	
	
'*********CHANGE HERE - To add additonal descriptive text from your memo to the new calendar entry - Change this section for calendar entry******	
'*********Follow the next 2 steps:  
'*********Step 1:  
'*********Uncomment the two lines of code below by removing the single quote preceding the lines of code so that the line of code become black text: 
'*********For example: 
'*********  'Set content = note.GetFirstItem("Body") 
'*********  'Call content.CopyItemToDocument(cnote, "Body") 
'*********Step 2:	
'*********Comment the line of code above by adding a single quote before the following line of code so the line of code becomes green text. 
'*********For example:	
'********** cnote.Body = ""	
	
	'Set content = note.GetFirstItem("Body")
	'Call content.CopyItemToDocument(cnote, "Body")
	
	
'**************************** End of Calendar Change Section ***********************	
	
'****************(1) ********* Begin Do Not Change Below  ******************************
	
	
	Dim calendar As notesView, oldVersions As notesDocumentCollection, oldVersion As notesDocument
	Set calendar = db.getView("($Calendar)")
	
	Set oldVersions = calendar.getAllDocumentsByKey(oldStartTime)
	Set oldVersion = oldVersions.getFirstDocument
	Removedit = "N"
	Do Until oldVersion Is Nothing
		
		If Instr(oldVersion.Subject(0), oldSubject) Then 
			
			Print "An entry for " & oldSubject & " was removed from your calendar."
			Msgbox "An entry for " & oldSubject & " was removed from your calendar." ,MB_OK+MB_ICONINFORMATION,"Successful"
			
			oldVersion.remove True
			Removedit = "Y"
			
		Else
			Set oldVersion = oldVersions.getNextDocument(oldVersion)
		End If 
	Loop
	
	If Removedit = "N" Then 
		Print "Calendar entry was not found. "		
	End If
	
	
	
	'Create calendar entry 
	
	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 = ""
	cnote.Subject=newSubject 'displays in calendar entry and when alarm is generated
	Call cnote.AppendItemValue("$BusyName", session.UserName)
	Call cnote.AppendItemValue("$BusyPriority", "1")
	Call cnote.AppendItemValue("$NoPurge", dt2)
	Call cnote.AppendItemValue("$PublicAccess", "1")
	
	Print "An entry for " & newSubject & " has been successfully added to your calendar."
	Msgbox "An entry for " & newSubject & " was succesfully added to your calendar." ,MB_OK+MB_ICONINFORMATION,"Successful"
	
	date1.adjustMinute -30
	cnote.ReplaceItemValue "$AlarmTime", date1
	cnote.ReplaceItemValue "$AlarmOffset", -30
	cnote.ReplaceItemValue "$Alarm", 1
	cnote.ReplaceItemValue "Alarms", "1"
	cnote.save True, True 
	cnote.putInFolder "($Alarms)"
	Print "Calendar entry added."
	
	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")     
	
'***********(1) >>>>>>>>>>End Do Not Change Above***********************************************************************************
	
	
'*********CHANGE HERE - Change Subject for the confirmation note ***********			
	maildoc.Subject = "I will call in for the Meeting"
	
'*********CHANGE HERE - Change Send To  for the confirmation note ***********	
'********To send the confirmation note to one person, just update the name 
'	maildoc.SendTo = "zzz@us.ibm.com"
	
'********To send the confirmation note multiple people, do the following:    
'*********Comment the code  above by adding a single quote before the line of code so the line of code becomes green text.
'*********For example:	
'*********  'maildoc.SendTo = "zzz@us.ibm.com"
'*********Then uncomment the following lines of code below by removing the single quote preceding the lines of code so that the line of code become black text:  
'*********Note:  the X in the SendToList (1 to X) must match the number of recipients 
'*********For example:  
'*********Dim SendToList(1 To 2) As String
'*********SendToList(1) = "1st notes id"
'*********SendToList(2) = "2nd notes id"
'*********Call maildoc.ReplaceItemValue("SendTo",SendToList)
	
'	Dim SendToList(1 To 3) As String
'	SendToList(1) = "1st notes id"
'	SendToList(2) = "2nd notes id"
'	SendToList(3) =  "3rd notes id"
'	Call maildoc.ReplaceItemValue("SendTo",SendToList)
	
'*********CHANGE HERE - Change CC for the confirmation note ***********
	maildoc.CopyTo = ""
	
'*********CHANGE HERE - Change BCC for the confirmation note ***********
	maildoc.BlindCopyTo = ""
	
'*********CHANGE HERE - Change Body for the confirmation note ***********
	Call rtitem.AppendText("I will call in for the Meeting")
	
'*********CHANGE HERE - To disable sending the confirmation note add a quote before the following line  so that the text becomes green
'	Call maildoc.Send(False)
	
'************************ End of Mail Reply Notification Change Section ***********************	
	Print "Operation complete."
	
	
End Sub

Open in new window

Comment
Watch Question

Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
great job !  thank you so much !  works like a charm !

Author

Commented:
Thank you , thank you, thank you !

Commented:
I'm glad that it worked, but note that this code will remove all documents that fall on that day if they have oldSubject anywhere in their subject. Previously only the first row of the subject was checked.
Watch for unwanted removals...

MbĀ¤

Author

Commented:
The start and end time has to be exact as well.  After testing, it appears that it only removes the first entry it sees if there are multiples with same time and same subject.  I guess it could be rare situations where the time and subject are exact - the potential to remove the wrong entry is apparent in this situation.  Maybe should check for 2nd line of subject or 1st line of body.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.