Creating Invitations using Visual Basic - please help!

Hi all,

kinda banging my head against the wall here, and could do with some advice.

I am trying to write a piece of VB (it will be ASP eventually) which will take a set of data (meeting title, start time, attendee email addresses, etc) from our app, and interface with Lotus Notes to create a Lotus Notes Meeting/Invitation and then send out the Invitation to the Attendees via Lotus Notes e-mail. Ideally, we would like to allow the user to be able to manually edit the Invitation before it is sent to the Attendees, but I think that’s a bit far away at the moment.

So, I am using the Notes COM Toolkit to do this, and have now ran into a wall. Although I am able to create the Meeting within my personal notes database, Notes NEVER sends the Invitation to any of the listed Attendees, no matter if I edit the Meeting within Notes itself. It is basically useless.

Earlier today, I discovered the NotesDocument.Send method, which helped me a little. My Invitations are now sent to the Attendees, but when opened in Notes, are not in ‘Invitation’ format, and are instead presented as a standard plain text email, with no ‘Accept’, ‘Deny’-type buttons.

Also, if I then rerun my VB routine a second time, I get a “-2147217461 - Database Open Failed (%1)” error - not helpful. Removing the call to Send() eliminates the error.

So I ask:

  1. Do I have to use the Send() method to get the Invitations sent out? If so, any ideas about this “-214…” error?

  2. How do I get the sent message to appear as an Invitation rather than just a standard bloody email!?

So frustrating for something so simple!

Here is my routine:

Sub CreateNotesMeeting()

On Error GoTo ErrorHandler

Dim objNotesSession As NotesSession

Dim objNotesDbDirectory As NotesDbDirectory

Dim objNotesDatabase As NotesDatabase

Dim objNotesDocument As NotesDocument

Dim objNotesDtFrom As NotesDateTime

Dim objNotesDtTo As NotesDateTime

Dim objNotesRichTextItem As NotesRichTextItem

    

Set objNotesSession = New NotesSession

    

Call objNotesSession.Initialize



Set objNotesDbDirectory = objNotesSession.GetDbDirectory("")

Set objNotesDatabase = objNotesDbDirectory.OpenMailDatabase()

    

'Set objNotesDatabase = objNotesSession.GetDatabase("", "mail\amcnab.nsf")

Set objNotesDocument = objNotesDatabase.CreateDocument

Set objNotesDtFrom = objNotesSession.CreateDateTime("2004-04-21 15:00:00")

Set objNotesDtTo = objNotesSession.CreateDateTime("2004-04-21 16:00:00")



Set objNotesRichTextItem = objNotesDocument.CreateRichTextItem("Body")



'## Appointment Type - Meeting

Call objNotesDocument.ReplaceItemValue("AppointmentType", "3")

        

'## General Meeting Info

Call objNotesDocument.ReplaceItemValue("Form", "Appointment")

Call objNotesDocument.ReplaceItemValue("Subject", "Test Meeting 3 Subject")



'commented line replaced with mulit-line body example

'Call objNotesDocument.ReplaceItemValue("Body", strBody)

objNotesRichTextItem.AppendText ("This is line 1")

objNotesRichTextItem.AddNewLine

objNotesRichTextItem.AppendText ("This is line 2")

    

Call objNotesDocument.ReplaceItemValue("Location", "Test Meeting 3 Location")

Call objNotesDocument.ReplaceItemValue("Room", "Test Meeting 3 Room")



'## Who sent/created/chairs the Meeting

Call objNotesDocument.ReplaceItemValue("From", objNotesSession.UserName)

Call objNotesDocument.ReplaceItemValue("Chair", objNotesSession.UserName)



'## Time of meeting-related stuff

Call objNotesDocument.ReplaceItemValue("STARTDATETIME", objNotesDtFrom)

Call objNotesDocument.ReplaceItemValue("EndDateTime", objNotesDtTo)

Call objNotesDocument.ReplaceItemValue("CalendarDateTime", objNotesDtFrom)

Call objNotesDocument.ReplaceItemValue("StartTime", objNotesDtFrom)

Call objNotesDocument.ReplaceItemValue("EndTime", objNotesDtTo)

Call objNotesDocument.ReplaceItemValue("StartDate", objNotesDtFrom)

Call objNotesDocument.ReplaceItemValue("EndDate", objNotesDtTo)



'## Attendee-related data

Dim arrRequiredAttendeeName() As String

Dim arrRequiredAttendeeNameAndEmail() As String

        

arrRequiredAttendeeName = Split("XXX@XXX.com", ";", -1)

    

Call objNotesDocument.AppendItemValue("RequiredAttendees", arrRequiredAttendeeName)

Call objNotesDocument.AppendItemValue("AltRequiredNames", arrRequiredAttendeeName)

'Call objNotesDocument.AppendItemValue("INetRequiredNames", arrRequiredAttendeeNameAndEmail)

Call objNotesDocument.ReplaceItemValue("StorageRequiredNames", ".")



Call objNotesDocument.AppendItemValue("SendTo", arrRequiredAttendeeName)

Call objNotesDocument.AppendItemValue("NoticeType", "I")

        

'## System variables

Call objNotesDocument.ReplaceItemValue("$UpdatedBy", objNotesSession.UserName)

Call objNotesDocument.ReplaceItemValue("_ViewIcon", 158)



'Call objNotesDocument.ComputeWithForm(False, False)

Call objNotesDocument.Send(True, arrRequiredAttendeeName)

Call objNotesDocument.Save(True, True)



Set objNotesRichTextItem = Nothing

Set objNotesDtTo = Nothing

Set objNotesDtFrom = Nothing

Set objNotesDocument = Nothing

Set objNotesDatabase = Nothing

Set objNotesDbDirectory = Nothing

Set objNotesSession = Nothing

    

Exit Sub

ErrorHandler:

MsgBox Err.Number & " - " & Err.Description

End Sub

Subject: Creating Invitations using Visual Basic - please help!

My recommendation is to look at what is left behind on an invitation document within lotus notes. If you need to create an invitation within Lotus Notes using the “Island” location document. After you note those field you will be able to have a base for your VB code. I wonder if any of the field do not have the correct field type.

Did the appointment show up on the invitee’s calendar?

HTH – Cheers

Subject: Creating Invitations using Visual Basic - please help!

Andrew,
Here is a function that I created in one of my notes applications to create a
document of the meeting invitation type. It works fine on R5 and I think It
successfully passed my tests on 6,5 as well.

u>Notes ]
I do not know what half of the fields are for but some of them must exist;
others don’t and I just don’t know which ones are mandatory.
I deleted some additional code which are not relevant for the invitation itself
so you may see some declarations of variables that are not used.

Good luck.

Function MakeMeetingInvitation(docCur As NotesDocument, nmUserChair As
notesName , nmUserFrom As notesname, _
nmUserTo As NotesName) As NotesDocument
'This function creates a meeting invitation
Dim s As New notessession
Dim db As NotesDatabase
Dim docSession As NotesDocument
Dim docInvitation As notesdocument

Dim vrnStartDate As Variant
Dim vrnEndDate As Variant
Dim vrnStartTime As Variant
Dim vrnEndTime As Variant
Dim strLocation As String, strSessionInfo As String

Set db = docCur.parentDatabase
'----------------------------------------------------------------
'Getting information from Session sDocument
'----------------------------------------------------------------
Set docSession = GetParentDocument(db, docCur.ParentDocumentUNID)

If Not docSession Is Nothing Then
	strLocation = docSession.Session_Loc(0)
	strSessionInfo = docSession.Session_Subject(0)
End If


'Set nmUser = New NotesName (s.Username)
Set nmUserFrom = New NotesName("Learning&Education")

'-------------------------------------------------------
' READING DATE AND TIME FIELDS
'-------------------------------------------------------
'it is not necessary to use variable but it makes it easier to debug
vrnStartDate = Datevalue(docCur.Session_StartDate(0))
vrnEndDate =  Datevalue(docCur.Session_EndDate(0))
vrnStartTime = Timevalue(docCur.Session_StartTime(0))
vrnEndTime = Timevalue(docCur.Session_EndTime(0))

'-------------------------------------------------------
' CREATING INVITATION
'-------------------------------------------------------
Set docInvitation = db.createDocument

docInvitation.Form = "Notice"
docInvitation.~_ViewIcon = 133
docInvitation.~$PublicAccess = "1"
docInvitation.AppointmentType = "3"
docInvitation.AltChair = nmUserFrom.Abbreviated
docInvitation.AltRequiredNames = nmUserTo .Abbreviated
docInvitation.AltSendTo = nmUserTo.canonical + "@EMEA-BE"

'Chair cannot be the same as User and UserFrom or the accept buttons 

will not be visible. it cannot be empty either
docInvitation.Chair = nmUserChair.canonical

docInvitation.Location = strLocation
docInvitation.NoticeType = "I"
docInvitation.PostedDate = Now
docInvitation.Principal = nmUserFrom.canonical
docInvitation.RequiredAttendees = nmUserTo.abbreviated + "@EMEA-BE"
docInvitation.Subject = "Invitation : " + docCur.Course_Name(0)
docInvitation.SendTo =nmUserTo.canonical

docInvitation.StartDate = vrnStartDate + vrnStartTime
docInvitation.StartDateTime = vrnStartDate + vrnStartTime
docInvitation.StartTime = vrnStartDate + vrnStartTime
docInvitation.EndDate = vrnEndDate + vrnEndTime		
docInvitation.EndDateTime = vrnEndDate + vrnEndTime	
docInvitation.EndTime = vrnEndDate + vrnEndTime

docInvitation.Topic = docCur.Course_Name(0)

Dim strarrCSTrack(1) As String
strarrCSTrack(0) = "InitEventDescriptorFromNewNote by Notes Client on " 
  • nmUserFrom.Abbreviated + “(” & Trim(s.NotesVersion) & ") at " & Cstr(Now)
    strarrCSTrack(1) = "SendPrimaryMeetingRequest by Notes Client on " +
    nmUserFrom.Abbreviated + “(” & Trim(s.NotesVersion) & ") at " & Cstr(Now)

    docInvitation.~$Alarm = 1
    docInvitation.~$AlarmOffset = -30
    docInvitation.~$AltPrincipal = nmUserFrom.canonical
    docInvitation.~$CSTrack = strarrCSTrack
    docInvitation.~$CSVersion = “2”
    docInvitation.~$ExpandGroups = “3”
    docInvitation.~$LangChair = “”
    docInvitation.~$LangPrincipal = “”
    docInvitation.~$Mailer = "Lotus Notes " + Strleft(s.notesVersion, “|”,

    • " " + Trim(Strright(s.notesVersion, “|”, 1))
      docInvitation.~$NameLanguageTags = “en”
      docInvitation.~$NoPurge = vrnStartDate + vrnStartTime
      docInvitation.~$StorageTo = “1”
      docInvitation.~$StorageCc = “”
      docInvitation.~$SMTPKeepNotesItems = “1”
      docInvitation.~$WebFlags = “J”

    Dim itemSign As NotesItem
    Set itemSign = New NotesItem(docInvitation, “Sign”, “0”)

    docInvitation.Alarms = “1”
    docInvitation.AltCopyTo = “”
    docInvitation.APPTUNID = docInvitation.universalID
    docInvitation.BookFreeTime = “”
    docInvitation.CopyTo = “”
    docInvitation.FromCategories = “”
    docInvitation.INetSendTo = “.”
    docInvitation.INetCopyTo = “”
    docInvitation.INetRequiredNames = “.”
    docInvitation.Logo = “stdNotesLtr0”
    docInvitation.MailFirstPass = “1”
    docInvitation.MAILOPTIONS = “”
    docInvitation.OrgConfidential = “”
    docInvitation.Repeats = “”
    docInvitation.RoomToReserve = “”
    docInvitation.Resources = “”
    docInvitation.SequenceNum = 1
    docInvitation.StorageRequiredNames = “1”
    docInvitation.WebCategory=“”
    docInvitation.WebDateTimeInit = “1”

    'No Counter proposal + No responses
    '---------------------------------------------------------
    docInvitation.Broadcast = “1”
    'docInvitation.PreventCounter = “1”
    Set MakeMeetingInvitation = docInvitation

End Function