Create Calendar Entry

Hi all,

I just want to create calendar entries (type anniversary, repeating each year for the range of 10 years) in the mailfile.

I tried out the following:

Function createNotesCalEntry ( odoc As notesdocument )

'odoc is the email from the inbox which should be transfered now to the calendar

' declared global - init in initialize ---- Dim odbthis As NotesDatabase 



Dim odocmailfile As NotesDocument

Dim myitem As Variant

Dim sBody As String

Dim sSubject As String



Dim startdate As New NotesDateTime(odoc.postedDate(0))

Dim enddate As NotesDateTime

Dim tempDate As New NotesDateTime (startdate.DateOnly + " 09:00 AM")

Dim obodyitem As NotesRichTextItem



Call tempdate.AdjustDay(+1)

Set startdate = New NotesDateTime (tempdate.DateOnly + " "  + tempdate.TimeOnly )

Call tempdate.AdjustMinute(+15) '15 minutes later

Set enddate = New NotesDateTime (tempdate.DateOnly + " "  + tempdate.TimeOnly )

Set tempdate = Nothing



Set obodyitem = odoc.GetFirstItem ("Body")



sBody = obodyitem.GetFormattedText(False,0)

sSubject = Mid(sBody, Instr(1, sBody, Chr(13))+4, Len(sBody)-2 ) + " Geburtstagsreminder"



Set myitem  = New notesdocument(odbthis)

With myitem

	.Form = "Appointment"

	.AppointmentType = "1"

	.Subject = sSubject

	

	'start

	.StartDate = startDate.LSGMTTime

	.StartDateTime = startDate.LSGMTTime

	.StartTime = startDate.LSGMTTime

	

	'end

	.EndDate = endDate.LSGMTTime

	.EndDateTime = endDate.LSGMTTime

	.EndTime = endDate.LSGMTTime

	

	.Principal = osession.UserName 

	.From = osession.UserName 

	.Body = sBody

	.BookFreeTime = "1"

	.Repeats = "1"

	.RepeatStartDate = startDate.LSGMTTime

	

End With



Call myitem.replaceitemvalue("$AlarmDescription", sSubject)

Call myitem.replaceitemvalue("$Alarm", "1")

Call myitem.replaceitemvalue("$AlarmSound", "notify")

Call myitem.replaceitemvalue("$AlarmOffset", "-1440")

'Call myitem.replaceitemvalue("$AlarmUnit", "D")

Call myitem.computewithform(True, True)

Call myitem.Save( True, False)

End Function

I#m using the R6 standard mail template.

This creates an entry that is NOT editable in all fields.

The recurrence is not set properly.

The view “All documents” shows a different icon in front of the document - when I create a anniversary doc manually then there is a small papper showing the number 18 (like notes icon 63) - my script instead creates an icon like the notes icon number 58 and a second one.

Can someone give me a hint which fields i have to set in which way?

I’m out of ideas :-//

Thanks.

alex

Subject: Anniversary in LotusScript: Code

I tried hard to create repeating anniversary documents in the background.

First of all you have to know, that a main document is created and for all repeating entries there is one response document holding the information.

This code worked for me:

Sub createEntry(sBirthday As String, sSubject As String)

Dim docNew As NotesDocument

Dim docResp As notesdocument

Dim iYear, iCnt, i As Integer

Dim sYear As String

Dim vCalDatRepeat() As Variant

Dim sCalDat As String	

'iRepeat: Number of Entries

'iAlarm: 6 if you want Alarm-Function

'Birthday Date

iYear = Year(Now)

iCnt = 0



For i = iCnt To iRepeat-1

	Redim Preserve vCalDatRepeat(i)

	sYear = Cstr(iYear + iCnt)

	sCalDat = Left(sBirthday,6)

	sCalDat = sCalDat + sYear

	vCalDatRepeat(iCnt) = Cdat(sCalDat)

	iCnt = iCnt + 1

Next



Set docNew = dbCal.CreateDocument	

Call createCommonFields(docNew, sCalDat, sBirthday, sSubject, vCalDatRepeat)

'Create Repeat-Dokuments

If iRepeat > 1 Then

	

	Call createRepeatFields(docNew, sCalDat, vCalDatRepeat)

	docNew.ApptUNID = docNew.UniversalID

	Call docNew.ComputeWithForm(True,False)

	Call docNew.Save(True,False)

	

	'Create RESPONSE

	Set docResp = dbCal.CreateDocument

	Call docResp.MakeResponse( docNew)

	Call createCommonFields(docResp, sCalDat, sBirthday, sSubject, vCalDatRepeat)

	Call createRepeatFields(docResp, sCalDat, vCalDatRepeat)

	docResp.ReplaceItemValue "$CSFlags", "i"

	docResp.~$RefOptions = "1"

	docResp.ApptUNID = docNew.UniversalID

	docResp.tmpOwnerHW = "0"

	docResp.WebDateTimeInit = "1"

	docResp.OrgState ="x"

	docResp.CalendarDateTime = vCalDatRepeat

	docResp.OriginalStartDate = Cdat(sCalDat)

	docResp.OriginalModTime = Cdat(sCalDat)

	'Remove Items

	Call docResp.RemoveItem( "RepeatDates" )

	Call docResp.RemoveItem( "RepeatEndDates" )

	Call docResp.RemoveItem( "RepeatFor" )

	Call docResp.RemoveItem( "RepeatForUnit" )

	Call docResp.RemoveItem( "RepeatHow" )

	Call docResp.RemoveItem( "RepeatInterval" )

	Call docResp.RemoveItem( "RepeatStartDate" )

	Call docResp.RemoveItem( "RepeatUnit" )

	Call docResp.RemoveItem( "RepeatWeekends" )

	Call docResp.ComputeWithForm(True,False)

	Call docResp.Save(True,False)

	If iAlarm = 6 Then

		Call docResp.PutInFolder( "$Alarms" )

	End If

	

Else

	'No Repeat

	docNew.CalendarDateTime = vCalDatRepeat

	Call docNew.ComputeWithForm(True,False)

	Call docNew.Save(True,False)

	If iAlarm = 6 Then

		Call docNew.PutInFolder( "$Alarms" )

	End If

	

End If

End Sub

Sub createCommonFields(doc As NotesDocument, sCalDat As String, sBirthday As String, sSubject As String, vCalDatRepeat As Variant)

Dim sExclude(1) As String

sExclude(0) = "D"

sExclude(1) = "S"



doc.~$BusyPriority = "1" 

doc.~$NoPurge = Cdat(sCalDat)



doc.Form = "Appointment"

doc.From = sUser

doc.Principal = sUser

doc.AppointmentType = "1"

doc.Subject = sSubject + " " + sBirthday

doc.Categories=""

doc.Body = ""

doc.Chair = sUser



doc.StartDateTime =vCalDatRepeat

'doc.StartDateTime =Cdat(sCalDat)

doc.StartDate = Cdat(sCalDat)

doc.EndDateTime = vCalDatRepeat

doc.EndDate = Cdat(sCalDat)

doc.StartTime = Cdat(sCalDat)

doc.EndTime = Cdat(sCalDat)



doc.OrgTable="A0"

doc.BookFreeTime=""

doc.Logo="StdNotesLtr15"

doc.ExcludeFromView= sExclude

doc.SequenceNum=1	

doc.~_ViewIcon = 63	

doc.Alarms= "" 	'Evt. Alarm auch noch einbauen.

doc.AltChair = sUser

'doc.OrgConfidential =

'doc.UpdateSeq =

'doc.Duration=1



doc.IsInfolineEntry = "YES"



If iAlarm = 6 Then

'Alarm

	doc.~$AlarmDescription = sSubject

	doc.~$Alarm = 1

	doc.~$AlarmOffset = -1440

	doc.Alarms = "1"

	'doc.~$AlarmSound = "notify"

End If

End Sub

Sub createRepeatFields(doc As NotesDocument, sCalDat As String, vCalDatRepeat As Variant)

'Fields für Repeat

doc.OrgRepeat = "1" 

doc.Repeats = "1"	

doc.~$CSFlags = "c"

doc.~$CSVersion = "2"

doc.RepeatDates =  vCalDatRepeat

doc.RepeatEndDates = vCalDatRepeat

doc.RepeatFor = iRepeat

doc.RepeatForUnit = "Y"

doc.RepeatHow = "F"

doc.RepeatInterval = "1"

doc.RepeatInstanceDates = vCalDatRepeat

doc.RepeatStartDate = Cdat(sCalDat)

doc.RepeatUnit = "Y"

doc.RepeatWeekends = "D"



doc.~$HFFlags = "1"

doc.~$SMTPKeepNotesItem = "1"



Dim atCSWISL (0 To 4) As String

atCSWISL(0)="$S:1"

atCSWISL(1)="$L:1"

atCSWISL(2)="$B:1"

atCSWISL(3)="$R:1"

atCSWISL(4)="$E:1"

doc.ReplaceItemValue "$CSWISL", atCSWISL 



Dim atWatched (0 To 4) As String

atWatched(0)="$S"

atWatched(1)="$L"

atWatched(2)="$B"

atWatched(3)="$R"

atWatched(4)="$E"

doc.ReplaceItemValue "$WatchedItems", atWatched

End Sub

Subject: Create Calendar Entry

Here is a library I created (based on Ike Eagle’s original code which only handled anniversary calendary entries) that can be used to create various types of personal calendar entries in a user’s mailfile, including repeat entries. While the functionality seems to work fine I cannot with any certainty grant assurances that the fidelity of the created calendar entries are 100% compatible with normal calendar entries.

-Ernie

Option Public

Option Declare

%REM

AUTHOR: Ernie Mercer (based on original code by Ike Eagle which only handled

anniversary calendary entries)

CREATED: 7/27/2005

This library can be used to create personal calendar entries in a user’s mailfile,

including repeat entries. For our purposes we needed this to take calendar

related documents such as vacation requests and team room calendar entries

and create appropriate documents in the user’s personal mail file calendar.

Given the right parameters it can create most any type of calendar entry:

appointment, event, reminder, anniversary, or (very limited) even a meeting

(but because of the complexity involved in sending notifications to invitees and rooms/

resources such notifications are not supported - users should then be advised to

manually create such meeting invitations). It can also be used to link to a source

document and/or copy over rich text from a source document.

The following parameters are required for proper processing of an entry:

dbCal As notesdatabase = the database to create the calendar entry in

sUser As String = the full heirarchical name of the person to create the calendar for

sType As String = the type of calendar entry (“Appointment”, “Reminder”, “Even”, “Anniversary”, “Meeting”)

sSubject As String = the title/subject of the calendar entry

vCalStartDates As Variant = a list array containing the start date of the entry (or start dates if a repeat entry)

vCalEndDates As Variant = a list array containing the end date of the entry (or end dates if a repeat entry)

RepeatFlags As Variant = A five element array containing necessary details for repeat entries

	'RepeatFlags(0) = RepeatForUnit

	'RepeatFlags(1) = RepeatHow

	'RepeatFlags(2) = RepeatInterval

	'RepeatFlags(3) = RepeatUnit

	'RepeatFlags(4) = RepeatWeekends

Comment As String = the comment to be entered in the Body of the calendar entry

docLink As NotesDocument = a document to be linked into the Body of the calendary entry

IncludeLink As Boolean = True/False - specifies whether or not to include a doc link to the docLink document

RTFField As String = an rich text field from the linked doc to be copy into the Body of the calendar entry

Location As String = the location of the appointment/event

%END REM

Function createCalEntry(dbCal As notesdatabase, _

sUser As String, sType As String, sSubject As String, vCalStartDates As Variant, _

vCalEndDates As Variant, RepeatFlags As Variant, Comment As String, _

docLink As NotesDocument, IncludeLink As Boolean, RTFField As String,_

Location As String) As Boolean

Dim wksp As New notesuiworkspace

Dim docNew As NotesDocument

Dim docResp As notesdocument

Dim iAlarm As Integer

Dim docNotice As NotesDocument

Dim EditEntry As Boolean

EditEntry = True



createCalEntry = False

'iRepeat: Number of Entries

'iAlarm: 6 if you want Alarm-Function

Set docNew = dbCal.CreateDocument

Call createCommonFields(docNew, sUser, sType, sSubject, _

vCalStartDates, vCalEndDates, Comment, docLink, IncludeLink, RTFField, Location)

'Create Repeat-Documents

If Ubound(vCalStartDates) > 1 Then

	

	Call createRepeatFields(docNew, vCalStartDates, vCalEndDates, RepeatFlags)

	docNew.ApptUNID = docNew.UniversalID

%REM

	If EditEntry = True Then

		Call wksp.EditDocument(True,docNew)

		createCalEntry = True

		Exit Function

	End If

%END REM

	Call docNew.ComputeWithForm(True,False)

	Call docNew.Save(True,False)

'Create RESPONSE

	Set docResp = dbCal.CreateDocument

	Call docResp.MakeResponse( docNew)

	Call createCommonFields(docResp, sUser, sType, sSubject, _

	vCalStartDates, vCalEndDates, Comment, docLink, IncludeLink, _

	RTFField, Location)

	Call createRepeatFields(docResp, vCalStartDates, vCalEndDates, RepeatFlags)

	docResp.ReplaceItemValue "$CSFlags", "i"

	docResp.~$RefOptions = "1"

	docResp.ApptUNID = docNew.UniversalID

	docResp.tmpOwnerHW = "0"

	docResp.WebDateTimeInit = "1"

	docResp.OrgState ="x"

	docResp.CalendarDateTime = vCalStartDates

	docResp.OriginalStartDate = vCalStartDates(0)

	docResp.OriginalModTime = vCalStartDates(0)

'Remove Items

	Call docResp.RemoveItem( "RepeatDates" )

	Call docResp.RemoveItem( "RepeatEndDates" )

	Call docResp.RemoveItem( "RepeatFor" )

	Call docResp.RemoveItem( "RepeatForUnit" )

	Call docResp.RemoveItem( "RepeatHow" )

	Call docResp.RemoveItem( "RepeatInterval" )

	Call docResp.RemoveItem( "RepeatStartDate" )

	Call docResp.RemoveItem( "RepeatUnit" )

	Call docResp.RemoveItem( "RepeatWeekends" )

	docResp.AdlinkCustomCalendarEntry = "Yes"

	Call docResp.ComputeWithForm(True,False)

	Call docResp.Save(True,False)

	If iAlarm = 6 Then

		Call docResp.PutInFolder( "$Alarms" )

	End If

	

	'send any required notifications

%REM (but because of the complexity involved in sending notifications to invitees and rooms/

resources such notifications are not supported - users should then be advised to

manually create such meeting invitations).

	If Isarray(invitees) Then

		Set docNotice = dbCal.CreateDocument()

		Call docResp.CopyAllItems(docNotice)

		With docNotice

			.RemoveItem("$Ref")

			.RemoveItem("CalendarDateTime")

			.RemoveItem("RepeatInstanceDates")

			.EndDateTime = vCalEndDates(0)

			.Form = "Notice"

			.PostedDate = Now

			.RepeatDates = vCalStartDates

			.RepeatEndDates = vCalEndDates

			.RepeatStartDate = vCalStartDates(0)

			.SendTo = invitees

			.StartDateTime = vCalStartDates(0)

			.~_ViewIcon = 133

			Call docNotice.ComputeWithForm(True,False)

			Call .Send(False)

		End With

		Set docNotice = Nothing

		With docResp

			.PostedDate = Now

			Call .Save(True,False)

		End With

	End If

%END REM

Else

'No Repeat

	docNew.CalendarDateTime = vCalStartDates

	docNew.AdlinkCustomCalendarEntry = "Yes"

	Call docNew.ComputeWithForm(True,False)

	Call docNew.Save(True,False)

	If iAlarm = 6 Then

		Call docNew.PutInFolder( "$Alarms" )

	End If

	

	'send any required notifications

%REM (but because of the complexity involved in sending notifications to invitees and rooms/

resources such notifications are not supported - users should be advised to

manually create such meeting invitations).

	If Isarray(invitees) Then

		Set docNotice = dbCal.CreateDocument()

		Call docNew.CopyAllItems(docNotice)

		With docNotice

			.RemoveItem("$Ref")

			.RemoveItem("CalendarDateTime")

			.RemoveItem("RepeatInstanceDates")

			.EndDateTime = vCalEndDates(0)

			.Form = "Notice"

			.PostedDate = Now

			.RepeatDates = vCalStartDates

			.RepeatEndDates = vCalEndDates

			.RepeatStartDate = vCalStartDates(0)

			.SendTo = invitees

			.StartDateTime = vCalStartDates(0)

			.~_ViewIcon = 133

			Call docNotice.ComputeWithForm(True,False)

			Call .Send(False)

		End With

		Set docNotice = Nothing

		With docNew

			.PostedDate = Now

			Call .Save(True,False)

		End With

	End If

%END REM

End If

’ If Isarray(invitees) Then

’ Messagebox "The entry has been saved to your calendar and notifications " &_

’ “have been sent the invitees.”, 0, “Calendar Updated Successfully”

’ Else

Messagebox "The entry has been saved to your calendar.",_

0, "Calendar Updated Successfully"

’ End If

createCalEntry = True

End Function

Sub createCommonFields(docNew As NotesDocument, sUser As String, _

sType As String, sSubject As String, vCalStartDates As Variant, vCalEndDates As Variant, _

Comment As String, docLink As NotesDocument, IncludeLink As Boolean, _

RTFField As String, Location As String)

Dim sExclude(1) As String

Dim iAlarm As Integer



sExclude(0) = "D"

sExclude(1) = "S"



With docNew

	.~$BusyPriority = "1"

	.~$NoPurge = vCalStartDates(0)

	.~$PublicAccess = "1"

	

	.Form = "Appointment"

	.From = sUser

	.Principal = sUser

	Select Case sType

	Case "Appointment"

		.AppointmentType = "0"

		.OrgTable="C0"

		.~_ViewIcon = 160

	Case "Anniversary"

		.AppointmentType = "1"

		.OrgTable="A0"

		.~_ViewIcon = 63

	Case "Event"

		.AppointmentType = "2"

		.OrgTable="P0"

		.~_ViewIcon = 9

	Case "Meeting"

		.AppointmentType = "3"

		.OrgTable="C0"

		.~_ViewIcon = 158

		'.RequiredAttendees = Invitees

	Case "Reminder"

		.AppointmentType = "4"

		.OrgTable="C0"

		.~_ViewIcon = 10

	End Select

	

	.Subject = sSubject

	.Categories=""

	.Chair = sUser

	

	.StartDateTime =vCalStartDates

	.StartDate = vCalStartDates(0)

	.StartTime = vCalStartDates(0)

	.EndDateTime = vCalEndDates

	.EndDate = vCalEndDates(0)

	.EndTime = vCalEndDates(0)

	.BookFreeTime=""

	.Logo="StdNotesLtr15"

	.ExcludeFromView= sExclude

	.SequenceNum=1

	.Alarms= "" 'Evt. Alarm auch noch einbauen.

	.AltChair = sUser

	.Location = Location

	'.Resources = Resources

	'.OrgConfidential =

	'.UpdateSeq =

	'.Duration=1

	

	'If Isarray(invitees) Then

	'	.RequiredAttendees = invitees

	'End If

	

	'if we are passed a linking document and the name of a rich text field

	'then process accordingly, else just write out the comment to the Body field

	If Not(docLink Is Nothing) And RTFField <> "" Then

		Call handleRichTextItem(docNew, docLink, IncludeLink, RTFField, comment)

	Else

		.Body = comment$

	End If

	

	

	.IsInfolineEntry = "YES"

	

	If iAlarm = 6 Then

'Alarm

		.~$AlarmDescription = sSubject

		.~$Alarm = 1

		.~$AlarmOffset = -1440

		.Alarms = "1"

		'.~$AlarmSound = "notify"

	End If

End With

End Sub

Sub createRepeatFields(doc As NotesDocument, vCalStartDates As Variant, _

vCalEndDates As Variant, RepeatFlags As Variant)

'RepeatFlags(0) = RepeatForUnit

'RepeatFlags(1) = RepeatHow

'RepeatFlags(2) = RepeatInterval

'RepeatFlags(3) = RepeatUnit

'RepeatFlags(4) = RepeatWeekends

'Fields for Repeat

doc.OrgRepeat = "1"

doc.Repeats = "1"

doc.~$CSFlags = "c"

doc.~$CSVersion = "2"

doc.RepeatDates = vCalStartDates

doc.RepeatEndDates = vCalEndDates

doc.RepeatFor = Ubound(vCalStartDates)  'iRepeat

doc.RepeatForUnit = RepeatFlags(0)

doc.RepeatHow = RepeatFlags(1)

doc.RepeatInterval = RepeatFlags(2)

doc.RepeatInstanceDates = vCalStartDates

doc.RepeatStartDate = vCalStartDates

doc.RepeatUnit = RepeatFlags(3)

doc.RepeatWeekends = RepeatFlags(4)



doc.~$HFFlags = "1"

doc.~$SMTPKeepNotesItem = "1"



Dim atCSWISL (0 To 4) As String

atCSWISL(0)="$S:1"

atCSWISL(1)="$L:1"

atCSWISL(2)="$B:1"

atCSWISL(3)="$R:1"

atCSWISL(4)="$E:1"

doc.ReplaceItemValue "$CSWISL", atCSWISL



Dim atWatched (0 To 4) As String

atWatched(0)="$S"

atWatched(1)="$L"

atWatched(2)="$B"

atWatched(3)="$R"

atWatched(4)="$E"

doc.ReplaceItemValue "$WatchedItems", atWatched

End Sub

Function handleRichTextItem(docTarget As NotesDocument, docLink As Notesdocument,_

IncludeLink As Boolean, RTFField As String, comment As String) As Boolean

HandleRichTextItem = False

Dim rtitem As notesrichtextitem

Dim rtnav As notesrichtextnavigator



'This function will copy a rich text item from a source doc to the new calendar entry,

'and it will also create a doc link to the source document if required.

'Otherwise it will simply append the comment the Body field of the new calendar entry



Set rtitem = docLink.GetFirstItem(RTFField)

If Not(rtitem Is Nothing) Then 'not a new doc, so we can access the rich text body field

	If rtitem.GetUnFormattedText <> "" Then 'see if we have data in the field

		If IncludeLink = True Then

			Call rtitem.CopyItemToDocument(DocTarget, "Body")

			Set rtitem = docTarget.GetFirstItem("Body")

			Set rtnav=rtitem.CreateNavigator

			If Not rtnav Is Nothing Then

				Call rtnav.FindFirstElement(RTELEM_TYPE_TEXTPARAGRAPH)

				Call rtitem.BeginInsert( rtnav, False ) 'move to beginning of rich text item

				Call rtItem.AppendText(comment$ & " -->")

				Call rtitem.AppendDocLink( docLink, "Link" )

				Call rtitem.AddNewline(2)

				Call rtitem.AppendText("---------------------------------------------------------------------------------------")

				Call rtitem.AddNewline(2)

				Call rtitem.EndInsert()

				Call rtitem.update

			End If

		Else

			Call rtitem.CopyItemToDocument(DocTarget, "Body")

			Set rtitem = docTarget.GetFirstItem("Body")

			Call rtitem.AddNewline(2)

			Call rtItem.AppendText(comment$)

		End If

	Else 'either it's a new document or there are no values in the field

		Set rtitem = New NotesRichTextItem( docTarget, "Body" )

		If Not(rtitem Is Nothing) Then

			If IncludeLink = True Then

				Call rtItem.AppendText(comment$ & " -->")

				Call rtitem.AppendDocLink( docLink, "Link" )

				Call rtitem.addnewline(2)

				Call rtItem.AppendText("---------------------------------------------------------")

				Call rtitem.update

			Else

				docTarget.Body = comment$

			End If

		Else

			docTarget.Body = comment$

		End If

	End If

End If



HandleRichTextItem = True

End Function

Subject: RE: Create Calendar Entry

Ernie,

I followed your method to create a reminder with Alarm, the only problem is that the Alarm is not triggered. I am using Notes Client/Domino 7.

The same reminder create by Code, when I change it by UI (Notes Client), the Alarm is triggered without any problem.

Please help.

Tarek.

Subject: RE: Create Calendar Entry

You need to put the reminder into the $Alarms folder by using the following line of code

Call ApptDoc.PutInFolder("$Alarms")