Create and update Calendar reminders from Notes document

At work I was asked yesterday if I could give the users a button to set reminders for meetings/actions directly from a document in one of our Notes applications. So I created a simple solution where I added two action buttons and a field to the form from which the calendar entry (reminder) would be created.

I wanted to share this code. It is nothing complicated, and the main functionality consists of some code Palmi Lord posted in LDD last year.

The new field on the form is called 'CalendarUNID' and will contain the Universal ID of the calendar entry. If the field is blank, I will display the 'Add to Calendar' button, if it contains a value I will display the button 'Update Calendar Entry' instead. This field is also used by the update function to get to the original calendar entry. Note that the reminder is created in the current user's calendar, and can only be successfully updated by the same user.
The date field used is named 'InspedtionDate', and I set the time to 8am. In the reminder I am also putting the address of the insured (the application is used by an insurance company) in the location field, and the insured/account name and policy number in the subject field.

 

'Add to Calendar' button

Hide-when formula:

CalendarUNID!="" | InspectionDate=""

Lotusscript Code:

Sub Click(Source As Button)   Dim ws As New NotesUIWorkspace   Dim uidoc As NotesUIDocument   Dim calentry As NotesDocument   Dim appdate As NotesDateTime   Dim location As String   Dim subject As String   Dim calunid As String    Set uidoc = ws.CurrentDocument   Set appdate = New NotesDateTime(uidoc.FieldGetText("InspectionDate") _ & " 08:00:00 AM")   ' Get physical location of insured   location = uidoc.FieldGetText("LocAddress") & ", "   location = location & uidoc.FieldGetText("LocCity") & ", "   location = location & uidoc.FieldGetText("LocState") & " " _ & uidoc.FieldGetText("LocZIP")   ' Build subject line for reminder   subject = "Inspection Due ("   subject = subject & uidoc.FieldGetText("AccountName") & " - "   subject = subject & uidoc.FieldGetText("PolicyNumber") & ")"   calunid = createReminder( appdate, location, subject)   Call uidoc.FieldSetText("CalendarUNID", calunid)   Call uidoc.Save()   Call uidoc.RefreshEnd SubFunction createReminder( dateTime As notesDateTime, _ location As String, subjectStr As String ) As String   Dim sess As New NotesSession   Dim userMailDb As New NotesDatabase( "", "" )   Call userMailDb.OpenMail   Dim reminderDoc As New NotesDocument( userMailDb )   Dim DTItem As NotesItem     With reminderDoc      .Form = "Appointment"      .ReplaceItemValue "$Alarm", 1      .ReplaceItemValue "$AlarmDescription", subjectStr      .ReplaceItemValue "$AlarmMemoOptions", ""      .ReplaceItemValue "$AlarmOffset", 0      .ReplaceItemValue "$AlarmUnit", "M"      .Subject = subjectStr      .Alarms = "1"      .CalendarDateTime = dateTime.lsLocalTime      .StartDate = dateTime.lsLocaltime      .StartTime = dateTime.lsLocaltime      .StartDateTime = dateTime.lsLocaltime        .EndDate = dateTime.lsLocaltime      .EndTime = dateTime.lsLocaltime      .EndDateTime = dateTime.lsLocaltime        .AppointmentType = "4"       .Location = location      .Category = "Service Plan Activity"      .Save True, False       .ComputeWithForm True, False      .Save True, False      .PutInFolder( "$Alarms" )   End With   createReminder = reminderDoc.UniversalIDEnd Function

'Update Calendar Entry' button:

Hide-when formula: CalendarUNID=""

Lotusscript Code:

Sub Click(Source As Button)   Dim ws As New NotesUIWorkspace   Dim uidoc As NotesUIDocument   Dim session As New NotesSession   Dim calentry As NotesDocument   Dim appdate As NotesDateTime   Dim location As String   Dim subject As String   Dim calunid As String   Set uidoc = ws.CurrentDocument   Set appdate = New NotesDateTime(uidoc.FieldGetText("InspectionDate") _ & " 08:00:00 AM")   ' Get physical location of insured   location = uidoc.FieldGetText("LocAddress") & ", "   location = location & uidoc.FieldGetText("LocCity") & ", "   location = location & uidoc.FieldGetText("LocState") & " " _ & uidoc.FieldGetText("LocZIP")   ' Build subject line for reminder   subject = "Inspection Due ("   subject = subject & uidoc.FieldGetText("AccountName") & " - "   subject = subject & uidoc.FieldGetText("PolicyNumber") & ")"   calunid = uidoc.FieldGetText("CalendarUNID")   Call updateReminder(calunid, appdate, location, subject)   Call uidoc.Save()   Call uidoc.RefreshEnd SubSub updateReminder(unid As String, dateTime As notesDateTime, _ location As String, subjectStr As String )   Dim sess As New NotesSession   Dim userMailDb As New NotesDatabase( "", "" )   Call userMailDb.OpenMail   Dim reminderDoc As NotesDocument   Dim DTItem As NotesItem    Set reminderDoc = userMailDB.GetDocumentByUNID(unid)   If reminderDoc Is Nothing Then      Msgbox "Failed to locate calendar entry."       Exit Sub    End If   With reminderDoc       .ReplaceItemValue "$AlarmDescription", subjectStr     &n
bsp;.Subject = subjectStr      .CalendarDateTime = dateTime.lsLocalTime      .StartDate = dateTime.lsLocaltime       .StartTime = dateTime.lsLocaltime      .StartDateTime = dateTime.lsLocaltime         .EndDate = dateTime.lsLocaltime      .EndTime = dateTime.lsLocaltime      .EndDateTime = dateTime.lsLocaltime        .Location = location      .Save True, False      .ComputeWithForm True, False      .Save True, False   End WithEnd Sub

 

 

 

Leave a Reply