Solved

Remove a meeting in lotus notes using Visual Basic code

Posted on 2016-10-31
31
26 Views
Last Modified: 2016-11-09
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
0
Comment
Question by:Andrew Sebastian
  • 16
  • 15
31 Comments
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 41866877
How do you intend to identify the meeting?
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 41868364
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
0
 

Author Comment

by:Andrew Sebastian
ID: 41869750
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.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 41869758
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?
0
 

Author Comment

by:Andrew Sebastian
ID: 41869761
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
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 41869781
"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?
0
 

Author Comment

by:Andrew Sebastian
ID: 41869881
Yes,i should be able to remove meetings the application didn't make based on a given subject,start time and end time
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 41869936
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.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 41869940
0
 

Author Comment

by:Andrew Sebastian
ID: 41871737
Thank you, i will look it up
0
 

Author Comment

by:Andrew Sebastian
ID: 41871956
I tried to use the code that you provided but i get a COM cast error and can't figure it out
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 41871993
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?
0
 

Author Comment

by:Andrew Sebastian
ID: 41872003
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
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 41872053
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.
0
 

Author Comment

by:Andrew Sebastian
ID: 41872060
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
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 41872062
And does your document have a field names CalendarDateTime? That field is indispensable, it should be set the same as StartDateTime.
0
 

Author Comment

by:Andrew Sebastian
ID: 41872080
By document do you mean the meeting or? Sorry i'm quite new to Lotus just started using it 1-2 weeks ago.
0
 
LVL 46

Assisted Solution

by:Sjef Bosman
Sjef Bosman earned 500 total points
ID: 41872128
Oh, sorry. Yes, in Notes we have Views and Documents. Views contains lists of Documents. A Document contains Items, but these are often referred to as Fields. More formally, Fields you'll find only in the Designer, in Forms, they serve to display document items. Clearer? Probably not... A document is like a record, a view is like a table. But not quite...

So, indeed, a Meeting is a document. I hope you have Notes and the mail application open, so you can see mails and meetings. A meeting has an item called Form with the value "Appointment" and an AppointmentType set to a specific value, 1, 2 , 3 or 4 (don't know which one). Use Notes, click a meeting and type Alt-Enter (or right-mouse + Document Properties).
0
 

Author Comment

by:Andrew Sebastian
ID: 41872149
Yes,it's type 3 (Meeting)
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 41872173
And the item CalendarDateTime? If there is one, what type is it?
0
 

Author Comment

by:Andrew Sebastian
ID: 41872207
There isn't one, there is only start date where you type the hour,local time and date
0
 
LVL 46

Assisted Solution

by:Sjef Bosman
Sjef Bosman earned 500 total points
ID: 41872297
The item isn't created?? CalendarDateTime is vital to the correct functioning of the Calendar view. Does the appointment you created appear in the Notes Calendar?

And what if you, prior to saving the appointment, type the F9 key (Windows) to recalculate the fields? Is the item created?
0
 

Author Comment

by:Andrew Sebastian
ID: 41873686
here is the interface that pops-up when i make the appointment with the code i wrote in the first place meeting.png
0
 
LVL 46

Assisted Solution

by:Sjef Bosman
Sjef Bosman earned 500 total points
ID: 41873698
I created a test Meeting using Notes, it has the CalendarDateTime item in it. Screen shot attached. Which Notes version do you have? Not that it really matters, unless it's 10 years old. And even then...
Document Properties
0
 

Author Comment

by:Andrew Sebastian
ID: 41873702
i use Notes 8.5
0
 

Author Comment

by:Andrew Sebastian
ID: 41873805
I checked and both CalendarDateTime and StartDateTime have the same type and the same hour stored
0
 

Accepted Solution

by:
Andrew Sebastian earned 0 total points
ID: 41873904
I found the solution, i just had to call doc.RemovePermanently(True) , here is the full code if anybody needs it ,thanks for all your help Sjef Bosman.

Option Explicit On
Imports Domino

Module Module1

    Dim sSrvr As String 'the mail server for the current user
    Dim MailDbName As String 'The current users notes mail database name
    Dim UserName As String 'The current users notes name
    Sub Main()

      
        Dim db As Object
        Dim ns As Object
        Dim view 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(sSrvr, MailDbName)
            Call db.OPENMAIL()
           

            view = db.GetView("Calendar")
            keydate = ns.CreateDateTime("11/04/16 02:30:00 PM")

            doc = view.GetDocumentByKey(keydate)
           
            If doc Is Nothing Then
                MsgBox("There are no entries for today!")
            Else
                doc.RemovePermanently(True)

          
            End If

        Catch ex As Exception
            MsgBox("Error! " + ex.ToString)
        End Try

    End Sub

End Module

Open in new window

0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 41873907
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... ;-)
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 41873914
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!
1
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 41874070
Suits me fine, thanks!
0
 

Author Closing Comment

by:Andrew Sebastian
ID: 41880264
I got the code figured out with the help of Sjef Bosman
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now