Link to home
Start Free TrialLog in
Avatar of Andrew Sebastian
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.NotesSession")
        sSrvr = Lotus_Session.GetEnvironmentString("MailServer", True)

        MailDbName = Lotus_Session.GetEnvironmentString("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.NotesUIWorkspace")
            Call workspace.SETTARGETFRAME("")
            
            On Error GoTo ErrCreate
            Call workspace.EDITDOCUMENT(True, beDoc)
            
            Sleep((500))
            err_count = 0
            
            On Error GoTo ErrHandler

            curDoc = workspace.CURRENTDOCUMENT
            Call curDoc.FIELDSETTEXT("StartDate", reser_start)
            Call curDoc.FIELDSETTEXT("StartTime", reser_start)
            Call curDoc.FIELDSETTEXT("EndDate", reser_end)
            Call curDoc.FIELDSETTEXT("EndTime", reser_end)
            Call curDoc.Refresh()
            
            'Bring the window to the front
            rc = ShowWindow(lotusWindow, SW_SHOW)
            rc = SetForegroundWindow(lotusWindow)
            
            '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
Avatar of Sjef Bosman
Sjef Bosman
Flag of France image

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
Avatar of Andrew Sebastian
Andrew Sebastian

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?
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?
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.
Thank you, i will look it up
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?
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.
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.NotesSession")
            ' sSrvr = ns.GetEnvironmentString("MailServer", True)
            ' MailDbName = ns.GetEnvironmentString("MailFile", True)
            'connection to the database
            db = ns.GetDatabase("", "")
            Call db.OPENMAIL()
           

            view = db.GetView("Calendar")
            keydate = ns.CreateDateTime("11/03/2016 15:30:00")
            keys(0) = keydate

            doc = view.GetDocumentByKey(keydate)

            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.
By document do you mean the meeting or? Sorry i'm quite new to Lotus just started using it 1-2 weeks ago.
SOLUTION
Avatar of Sjef Bosman
Sjef Bosman
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes,it's type 3 (Meeting)
And the item CalendarDateTime? If there is one, what type is it?
There isn't one, there is only start date where you type the hour,local time and date
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
here is the interface that pops-up when i make the appointment with the code i wrote in the first place User generated image
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i use Notes 8.5
I checked and both CalendarDateTime and StartDateTime have the same type and the same hour stored
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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!
Suits me fine, thanks!
I got the code figured out with the help of Sjef Bosman