Andrew Sebastian
asked on
Remove a meeting in lotus notes using Visual Basic code
I am trying to create an application that will remove a meeting from the calendar in Lotus Notes. So far i managed to write the code for the creation of the meeting but not the removal part,would appreciate if someone can help me. The code i used to create the meeting is this :
Private Sub Meeting(ByVal reser_type As String, ByVal reser_id As String, ByVal reser_by_mail As String, ByVal reser_by_name As String, ByVal usr_mail As String, ByVal usr_name As String, ByVal tb_op_mail As String, ByVal tb_op_name As String, ByVal tb_n As String, ByVal tb_r As String, ByVal reser_start As String, ByVal reser_end As String, ByVal project As String, ByVal req_project_cnf As String, ByVal reser_req_conf As String, ByVal tb_dec_n As String, ByVal stat As String, ByVal erase_in_file As String, ByVal com As String)
'Constnats for window handling
Const notesclass As String = "NOTES"
Const SW_SHOWMAXIMIZED As Short = 3
Const SW_SHOWMMINIZED As Short = 2
Const SW_SHOWWINDOW As Short = 1 '
Const SW_SHOW As Short = 5
Dim Lotus_Session As Object
Dim rc As Integer
Dim lotusWindow As Integer
Dim db As Object
Dim beDoc As Object 'back end document
Dim curDoc As Object 'front end document
Dim workspace As Object 'use front end classes to display to user
Dim body As String
Dim err_count As Short
Dim flag As Short
'Generate the variables for the connection
lotusWindow = FindWindow(notesclass, vbNullString)
rc = ShowWindow(lotusWindow, SW_SHOWMMINIZED)
Lotus_Session = CreateObject("Notes.NotesS ession")
sSrvr = Lotus_Session.GetEnvironme ntString(" MailServer ", True)
MailDbName = Lotus_Session.GetEnvironme ntString(" MailFile", True)
UserName = Lotus_Session.UserName
'connection to the database
db = Lotus_Session.GetDatabase( sSrvr, MailDbName)
If db.IsOpen = True Then
'database already opened
flag = 0
Else
'Open database
Call db.OPENMAIL()
flag = 14
End If
'Prepare the body for the appointment
body = "The following reservation was entered for you in the TEBENATOR:" & vbCrLf & "ID:" & vbTab & vbTab & vbTab & reser_id & vbCrLf & "Testbench:" & vbTab & vbTab & tb_n & ", " & tb_r & vbCrLf & "reserved By:" & vbTab & vbTab & reser_by_name & vbCrLf & "User:" & vbTab & vbTab & vbTab & usr_name & vbCrLf
If ((tb_op_name <> "") And (tb_op_name <> "not defined")) Then
body = body & "TB Operator:" & vbTab & vbTab & tb_op_name & " >> PLEASE CONFIRM IN THE TEBENATOR ONCE TESTBENCH IS READY TO USE, Menu Reserve > Edit Reservation <<" & vbCrLf
End If
If ((req_project_cnf <> "") And (req_project_cnf <> "not defined")) Then
body = body & "Project configuration:" & vbTab & project & " – " & req_project_cnf & vbCrLf
Else
body = body & "Project configuration:" & vbTab & project & vbCrLf
End If
If ((tb_dec_n <> "") And (tb_dec_n <> "not defined")) Then
body = body & "Confirmation needed by:" & vbTab & tb_dec_n & vbCrLf
End If
body = body & "Status:" & vbTab & vbTab & vbTab & stat & vbCrLf
If ((com <> "") And (com <> "not defined")) Then
body = body & "Comment by:" & vbTab & vbTab & reser_by_name & vbCrLf & com & vbCrLf
End If
'Create the document in the background and fill it
beDoc = db.CreateDocument
beDoc.Form = "Appointment"
beDoc.AppointmentType = "3"
If reser_type = "update" Then
beDoc.Subject = "TEBENATOR: Reservation update of Testbench " & tb_n
Else
beDoc.Subject = "TEBENATOR: Reservation of Testbench " & tb_n
End If
beDoc.Location = tb_n & ", " & tb_r
beDoc.body = body
beDoc.SendTo = tb_op_mail & ", " & usr_mail
beDoc.BusyPriority = "2"
beDoc.BookFreeTime = "1"
beDoc.body = body
'Bring the document to the front and add the rest
workspace = CreateObject("Notes.NotesU IWorkspace ")
Call workspace.SETTARGETFRAME(" ")
On Error GoTo ErrCreate
Call workspace.EDITDOCUMENT(Tru e, beDoc)
Sleep((500))
err_count = 0
On Error GoTo ErrHandler
curDoc = workspace.CURRENTDOCUMENT
Call curDoc.FIELDSETTEXT("Start Date", reser_start)
Call curDoc.FIELDSETTEXT("Start Time", reser_start)
Call curDoc.FIELDSETTEXT("EndDa te", reser_end)
Call curDoc.FIELDSETTEXT("EndTi me", reser_end)
Call curDoc.Refresh()
'Bring the window to the front
rc = ShowWindow(lotusWindow, SW_SHOW)
rc = SetForegroundWindow(lotusW indow)
'Reset all variables
Call Lotus_Session.Close()
Lotus_Session = Nothing
db = Nothing
beDoc = Nothing
curDoc = Nothing
workspace = Nothing
Exit Sub
ErrHandler:
Sleep((500))
err_count = err_count + 1
If err_count = (6 + flag) Then
MsgBox("Sorry there was an error during the creation of the appointment!" & vbCrLf & "If it is already created, please check all informations, especially the time settings!" & vbCrLf & "You can also delete the appointment and try it again!", MsgBoxStyle.Exclamation, "Error during generation of the Appointment")
Exit Sub
End If
Resume
ErrCreate:
MsgBox("Sorry there was an error during the creation of the appointment!" & vbCrLf & "It seems that there is an Dialog window of NOTES open!" & vbCrLf & "Please close it first and then close this window!", MsgBoxStyle.Exclamation, "Error during generation of the Appointment")
Resume
End Sub
Private Sub Meeting(ByVal reser_type As String, ByVal reser_id As String, ByVal reser_by_mail As String, ByVal reser_by_name As String, ByVal usr_mail As String, ByVal usr_name As String, ByVal tb_op_mail As String, ByVal tb_op_name As String, ByVal tb_n As String, ByVal tb_r As String, ByVal reser_start As String, ByVal reser_end As String, ByVal project As String, ByVal req_project_cnf As String, ByVal reser_req_conf As String, ByVal tb_dec_n As String, ByVal stat As String, ByVal erase_in_file As String, ByVal com As String)
'Constnats for window handling
Const notesclass As String = "NOTES"
Const SW_SHOWMAXIMIZED As Short = 3
Const SW_SHOWMMINIZED As Short = 2
Const SW_SHOWWINDOW As Short = 1 '
Const SW_SHOW As Short = 5
Dim Lotus_Session As Object
Dim rc As Integer
Dim lotusWindow As Integer
Dim db As Object
Dim beDoc As Object 'back end document
Dim curDoc As Object 'front end document
Dim workspace As Object 'use front end classes to display to user
Dim body As String
Dim err_count As Short
Dim flag As Short
'Generate the variables for the connection
lotusWindow = FindWindow(notesclass, vbNullString)
rc = ShowWindow(lotusWindow, SW_SHOWMMINIZED)
Lotus_Session = CreateObject("Notes.NotesS
sSrvr = Lotus_Session.GetEnvironme
MailDbName = Lotus_Session.GetEnvironme
UserName = Lotus_Session.UserName
'connection to the database
db = Lotus_Session.GetDatabase(
If db.IsOpen = True Then
'database already opened
flag = 0
Else
'Open database
Call db.OPENMAIL()
flag = 14
End If
'Prepare the body for the appointment
body = "The following reservation was entered for you in the TEBENATOR:" & vbCrLf & "ID:" & vbTab & vbTab & vbTab & reser_id & vbCrLf & "Testbench:" & vbTab & vbTab & tb_n & ", " & tb_r & vbCrLf & "reserved By:" & vbTab & vbTab & reser_by_name & vbCrLf & "User:" & vbTab & vbTab & vbTab & usr_name & vbCrLf
If ((tb_op_name <> "") And (tb_op_name <> "not defined")) Then
body = body & "TB Operator:" & vbTab & vbTab & tb_op_name & " >> PLEASE CONFIRM IN THE TEBENATOR ONCE TESTBENCH IS READY TO USE, Menu Reserve > Edit Reservation <<" & vbCrLf
End If
If ((req_project_cnf <> "") And (req_project_cnf <> "not defined")) Then
body = body & "Project configuration:" & vbTab & project & " – " & req_project_cnf & vbCrLf
Else
body = body & "Project configuration:" & vbTab & project & vbCrLf
End If
If ((tb_dec_n <> "") And (tb_dec_n <> "not defined")) Then
body = body & "Confirmation needed by:" & vbTab & tb_dec_n & vbCrLf
End If
body = body & "Status:" & vbTab & vbTab & vbTab & stat & vbCrLf
If ((com <> "") And (com <> "not defined")) Then
body = body & "Comment by:" & vbTab & vbTab & reser_by_name & vbCrLf & com & vbCrLf
End If
'Create the document in the background and fill it
beDoc = db.CreateDocument
beDoc.Form = "Appointment"
beDoc.AppointmentType = "3"
If reser_type = "update" Then
beDoc.Subject = "TEBENATOR: Reservation update of Testbench " & tb_n
Else
beDoc.Subject = "TEBENATOR: Reservation of Testbench " & tb_n
End If
beDoc.Location = tb_n & ", " & tb_r
beDoc.body = body
beDoc.SendTo = tb_op_mail & ", " & usr_mail
beDoc.BusyPriority = "2"
beDoc.BookFreeTime = "1"
beDoc.body = body
'Bring the document to the front and add the rest
workspace = CreateObject("Notes.NotesU
Call workspace.SETTARGETFRAME("
On Error GoTo ErrCreate
Call workspace.EDITDOCUMENT(Tru
Sleep((500))
err_count = 0
On Error GoTo ErrHandler
curDoc = workspace.CURRENTDOCUMENT
Call curDoc.FIELDSETTEXT("Start
Call curDoc.FIELDSETTEXT("Start
Call curDoc.FIELDSETTEXT("EndDa
Call curDoc.FIELDSETTEXT("EndTi
Call curDoc.Refresh()
'Bring the window to the front
rc = ShowWindow(lotusWindow, SW_SHOW)
rc = SetForegroundWindow(lotusW
'Reset all variables
Call Lotus_Session.Close()
Lotus_Session = Nothing
db = Nothing
beDoc = Nothing
curDoc = Nothing
workspace = Nothing
Exit Sub
ErrHandler:
Sleep((500))
err_count = err_count + 1
If err_count = (6 + flag) Then
MsgBox("Sorry there was an error during the creation of the appointment!" & vbCrLf & "If it is already created, please check all informations, especially the time settings!" & vbCrLf & "You can also delete the appointment and try it again!", MsgBoxStyle.Exclamation, "Error during generation of the Appointment")
Exit Sub
End If
Resume
ErrCreate:
MsgBox("Sorry there was an error during the creation of the appointment!" & vbCrLf & "It seems that there is an Dialog window of NOTES open!" & vbCrLf & "Please close it first and then close this window!", MsgBoxStyle.Exclamation, "Error during generation of the Appointment")
Resume
End Sub
How do you intend to identify the meeting?
And then there was silence... Ok, I'll explain my question. To be able to delete a meeting, you have to identify it, in order to grab it in the database or a view, and then delete it. Usually, it is not correct to delete someone's meeting. It would be better to send the person a message that the meeting is cancelled. To do that, you need to adhere to the meeting planning protocol.
Interesting read:
- https://www-10.lotus.com/ldd/ddwiki.nsf/dx/cs_schema_toc?open
- the Calendar & Scheduling API
- http://www.idonotes.com/idonotes/idonotes.nsf/dx/ibm-notes-9-introduces-new-calendaring-and-scheduling-cs-back-end-classes.htm
Interesting read:
- https://www-10.lotus.com/ldd/ddwiki.nsf/dx/cs_schema_toc?open
- the Calendar & Scheduling API
- http://www.idonotes.com/idonotes/idonotes.nsf/dx/ibm-notes-9-introduces-new-calendaring-and-scheduling-cs-back-end-classes.htm
ASKER
sorry about that,i was out of the office and i just got back,i don't actually know how to identify it i was just asked to create an application that deletes a meeting,similar to the code i wrote above.
Then you're missing some specifications, I'd say... Is it a function or subroutine they require, is it an interactive process, or what exactly do they want?
ASKER
it wasn't specified,when i asked they told me they need only the application ,as far as i understood they want to cancel appointments since the program i designed already does that
"Write a book and store it". That's doable.
They: "Remove a book".
You: "Any book?".
They: "No, a specific one".
You: "Ah, then I need to know which one?"
Seems logical to me...
In any case, you'll need to identify a Meeting, i.e. a Notes document in the user's mail database. What do you know about it? Date/time/place? Maybe its name? Or did you leave some id when you created the meeting? Do you also have to remove meetings your application didn't create, i.e. one of those created by the user?
They: "Remove a book".
You: "Any book?".
They: "No, a specific one".
You: "Ah, then I need to know which one?"
Seems logical to me...
In any case, you'll need to identify a Meeting, i.e. a Notes document in the user's mail database. What do you know about it? Date/time/place? Maybe its name? Or did you leave some id when you created the meeting? Do you also have to remove meetings your application didn't create, i.e. one of those created by the user?
ASKER
Yes,i should be able to remove meetings the application didn't make based on a given subject,start time and end time
Ah, subject, start time, end time... Good! But is that enough? Probably it is, in 99.5% of all cases, but should you be prepared also for meetings that were altered by the user in any way, which would make it impossible to find the meeting? Hence my question: when you created the meeting, did you leave some unique key in it that you store in your own database somewhere, which would make identification a 100% certainty?
Okay, finding back a meeting based on start time shouldn't be that hard. Basically it requires you to open the Calendar view and search the view based on the start time. In LotusScript:
Dim view As NotesView
Set view= db.GetView("Calendar")
Dim keys(0) as Variant
Dim keydate As NotesDateTime
Set keydate = New NotesDateTime("01/15/2000 13:30:00")
Set keys(0) = keydate
Dim doc as NotesDocument
Set doc= view.GetDocumentByKey(keys )
There could be multiple events at the same time. Check the Subject, or if you have it, the unique key you stored in it.
Okay, finding back a meeting based on start time shouldn't be that hard. Basically it requires you to open the Calendar view and search the view based on the start time. In LotusScript:
Dim view As NotesView
Set view= db.GetView("Calendar")
Dim keys(0) as Variant
Dim keydate As NotesDateTime
Set keydate = New NotesDateTime("01/15/2000 13:30:00")
Set keys(0) = keydate
Dim doc as NotesDocument
Set doc= view.GetDocumentByKey(keys
There could be multiple events at the same time. Check the Subject, or if you have it, the unique key you stored in it.
A maybe relevant and helpful question:
https://www.experts-exchange.com/questions/21357526/Check-free-time-on-LotusNotes-calendar-with-VBA.html
https://www.experts-exchange.com/questions/21357526/Check-free-time-on-LotusNotes-calendar-with-VBA.html
ASKER
Thank you, i will look it up
ASKER
I tried to use the code that you provided but i get a COM cast error and can't figure it out
I assume you have to declare every object as Object, instead of NotesXxxx. Plus, in VB there is no New NotesDateTime, that has to be session.CreateDateTime.
Could you give that a try?
Could you give that a try?
ASKER
yeah,i did it already but the doc is always empty even though i have the meeting in my calendar set up with the proper hours
What's your current code; the part that searches the meeting document?
Can you run it in debugging mode? I assume doc is Nothing, which means that the document isn't found.
Can you run it in debugging mode? I assume doc is Nothing, which means that the document isn't found.
ASKER
Sub Main()
Dim db As Object
Dim ns As Object
Dim view As Object
Dim keys(0) As Object
Dim keydate As Object
Dim doc As Object
Try
ns = CreateObject("Notes.NotesS ession")
' sSrvr = ns.GetEnvironmentString("M ailServer" , True)
' MailDbName = ns.GetEnvironmentString("M ailFile", True)
'connection to the database
db = ns.GetDatabase("", "")
Call db.OPENMAIL()
view = db.GetView("Calendar")
keydate = ns.CreateDateTime("11/03/2 016 15:30:00")
keys(0) = keydate
doc = view.GetDocumentByKey(keyd ate)
If doc Is Nothing Then
MsgBox("there are no entries for today!")
Else
MsgBox("The current reservation is:" & Environment.NewLine)
MsgBox(doc) (i have to convert this value since it prompt type)
End If
Catch ex As Exception
MsgBox("Error! " + ex.ToString)
End Try
End Sub
Dim db As Object
Dim ns As Object
Dim view As Object
Dim keys(0) As Object
Dim keydate As Object
Dim doc As Object
Try
ns = CreateObject("Notes.NotesS
' sSrvr = ns.GetEnvironmentString("M
' MailDbName = ns.GetEnvironmentString("M
'connection to the database
db = ns.GetDatabase("", "")
Call db.OPENMAIL()
view = db.GetView("Calendar")
keydate = ns.CreateDateTime("11/03/2
keys(0) = keydate
doc = view.GetDocumentByKey(keyd
If doc Is Nothing Then
MsgBox("there are no entries for today!")
Else
MsgBox("The current reservation is:" & Environment.NewLine)
MsgBox(doc) (i have to convert this value since it prompt type)
End If
Catch ex As Exception
MsgBox("Error! " + ex.ToString)
End Try
End Sub
And does your document have a field names CalendarDateTime? That field is indispensable, it should be set the same as StartDateTime.
ASKER
By document do you mean the meeting or? Sorry i'm quite new to Lotus just started using it 1-2 weeks ago.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes,it's type 3 (Meeting)
And the item CalendarDateTime? If there is one, what type is it?
ASKER
There isn't one, there is only start date where you type the hour,local time and date
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i use Notes 8.5
ASKER
I checked and both CalendarDateTime and StartDateTime have the same type and the same hour stored
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Then, according to all theory, you should be able to find the meeting document. Let me do some tests here, to see if I can find a meeting using the Calendar view. I'll be back... ;-)
Ah yes, the meeting still exists because the Remove only moves it to the Trash folder, when activated. Good that you found the missing element!
Just a warning: watch out when you search for a meeting that's supposed to have a start time of 1600 but was rescheduled somehow to 1700 and a new meeting was scheduled at 1600. The date/time key is not enough and also not necessarily unique, so better do some checks!
Just a warning: watch out when you search for a meeting that's supposed to have a start time of 1600 but was rescheduled somehow to 1700 and a new meeting was scheduled at 1600. The date/time key is not enough and also not necessarily unique, so better do some checks!
Suits me fine, thanks!
ASKER
I got the code figured out with the help of Sjef Bosman