Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 105
  • Last Modified:

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
0
Andrew Sebastian
Asked:
Andrew Sebastian
  • 16
  • 15
4 Solutions
 
Sjef BosmanGroupware ConsultantCommented:
How do you intend to identify the meeting?
0
 
Sjef BosmanGroupware ConsultantCommented:
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
 
Andrew SebastianAuthor Commented:
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
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
Sjef BosmanGroupware ConsultantCommented:
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
 
Andrew SebastianAuthor Commented:
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
 
Sjef BosmanGroupware ConsultantCommented:
"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
 
Andrew SebastianAuthor Commented:
Yes,i should be able to remove meetings the application didn't make based on a given subject,start time and end time
0
 
Sjef BosmanGroupware ConsultantCommented:
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
 
Sjef BosmanGroupware ConsultantCommented:
0
 
Andrew SebastianAuthor Commented:
Thank you, i will look it up
0
 
Andrew SebastianAuthor Commented:
I tried to use the code that you provided but i get a COM cast error and can't figure it out
0
 
Sjef BosmanGroupware ConsultantCommented:
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
 
Andrew SebastianAuthor Commented:
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
 
Sjef BosmanGroupware ConsultantCommented:
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
 
Andrew SebastianAuthor Commented:
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
 
Sjef BosmanGroupware ConsultantCommented:
And does your document have a field names CalendarDateTime? That field is indispensable, it should be set the same as StartDateTime.
0
 
Andrew SebastianAuthor Commented:
By document do you mean the meeting or? Sorry i'm quite new to Lotus just started using it 1-2 weeks ago.
0
 
Sjef BosmanGroupware ConsultantCommented:
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
 
Andrew SebastianAuthor Commented:
Yes,it's type 3 (Meeting)
0
 
Sjef BosmanGroupware ConsultantCommented:
And the item CalendarDateTime? If there is one, what type is it?
0
 
Andrew SebastianAuthor Commented:
There isn't one, there is only start date where you type the hour,local time and date
0
 
Sjef BosmanGroupware ConsultantCommented:
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
 
Andrew SebastianAuthor Commented:
here is the interface that pops-up when i make the appointment with the code i wrote in the first place meeting.png
0
 
Sjef BosmanGroupware ConsultantCommented:
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
 
Andrew SebastianAuthor Commented:
i use Notes 8.5
0
 
Andrew SebastianAuthor Commented:
I checked and both CalendarDateTime and StartDateTime have the same type and the same hour stored
0
 
Andrew SebastianAuthor Commented:
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
 
Sjef BosmanGroupware ConsultantCommented:
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
 
Sjef BosmanGroupware ConsultantCommented:
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
 
Sjef BosmanGroupware ConsultantCommented:
Suits me fine, thanks!
0
 
Andrew SebastianAuthor Commented:
I got the code figured out with the help of Sjef Bosman
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 16
  • 15
Tackle projects and never again get stuck behind a technical roadblock.
Join Now