LotusScript Calendar Agent Problem - Accept/Decline not working?

I have an agent that sends out a meeting notice to users. The problem is that when eacj user gets the meeting notice emailed to them, it is automatically added to their calendar without having them accept/decline it. Then if the user declines the meeting, the meeting notice is not removed from the calendar view.

I assume there is some field that is not being updated when the user hits decline??

Here is the code of the agent:

Sub Initialize

Dim ws As New NotesUIWorkspace

Dim s As New NotesSession

Dim db As New NotesDatabase("","")

Dim doc As NotesDocument, doc As NotesDocument, invitedoc As NotesDocument



Call db.OpenMail

Set doc = ws.CurrentDocument.Document

Set cdoc = db.CreateDocument

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

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

Call cdoc.ReplaceItemValue("_ViewIcon", 158)

Call cdoc.ReplaceItemValue("Chair", doc.Name)

Call cdoc.ReplaceItemValue("Principal", "ASG Toyota Event Calendar")

Call cdoc.ReplaceItemValue("Subject",doc.Description(0))

Call cdoc.ReplaceItemValue("Topic", doc.Description(0))

Call cdoc.ReplaceItemValue("Location", doc.SSNAArea(0))

Call cdoc.ReplaceItemValue("SequenceNum",1)

’ //read the datetime from the edstartdate field that user has typed in=

Dim d1 As NotesDateTime

Dim item As NotesItem

Set item = doc.GetFirstItem("StartDateTime")

Set d1 = item.DateTimeValue



Set domDateTime = s.CreateDateTime("" & d1.DateOnly & " " & d1.TimeOnly)



Call cdoc.ReplaceItemValue("CalendarDateTime", domDateTime.LSLocalTime)

Call cdoc.ReplaceItemValue("StartTime", domDateTime.LSLocalTime)

Call cdoc.ReplaceItemValue("StartDate",domDateTime.LSLocalTime)

Call cdoc.ReplaceItemValue("StartDateTime", domDateTime.LSLocalTime)

'//read the datetime from the edenddate field that user has typed in

Dim d2 As NotesDateTime

Set item = doc.GetFirstItem("EndDateTime")

Set d2 = item.DateTimeValue



Set domDateTime = s.CreateDateTime("" & d2.DateOnly & " " & d2.TimeOnly)

Call cdoc.ReplaceItemValue("EndDateTime", domDateTime.LSLocalTime)

Call cdoc.ReplaceItemValue("EndDate",domDateTime.LSLocalTime)

Call cdoc.ReplaceItemValue("EndTime",domDateTime.LSLocalTime)



Set ntitem = doc.ReplaceItemValue("ExcludeFromView", "D")

Call ntitem.AppendToTextList( "S" )



'Names from Address Book

'Dim sendTo As Variant

'Dim tempnamesdoc As NotesDocument

'Set tempnamesdoc = doc.Document

'sendTo = tempnamesdoc.tempnames



Call cdoc.ReplaceItemValue("RequiredAttendees", "Derek A Etnyre/NA/Johnson_Controls")

Call cdoc.ReplaceItemValue("SendTo","Derek A Etnyre/NA/Johnson_Controls")

Call cdoc.ReplaceItemValue("CopyTo", "")

Call cdoc.ReplaceItemValue("BlindCopyTo", "")

Call domDateTime.SetNow

Call cdoc.ReplaceItemValue( "PostedDate", domDateTime.LSLocalTime )

Call cdoc.ReplaceItemValue( "EnterSendTo", "" )

Call cdoc.ReplaceItemValue( "EnterCopyTo", "" )

Call cdoc.ReplaceItemValue( "EnterBlindCopyTo", "" )

Call cdoc.ReplaceItemValue( "$CSTrack", "Sent" )

Call cdoc.ReplaceItemValue( "$Mailer", "LN" )

Call cdoc.ReplaceItemValue( "$MessageID", "automatic@Localdomain" )

'Call cdoc.save(True, True, True) 

Call cdoc.Send(False)

Subject: LotusScript Calendar Agent Problem - My Solution

I finally got my calendar agent to work properly.

I wanted to create an Appointment that did not automatically get added to a users calendar until the user accepted it.

This article has a list of all of the required fields needed for Calendar Appointment. It is a must read for anyone creating calendar entires and appointments:

http://www-10.lotus.com/ldd/today.nsf/62f62847467a8f78052568a80055b380/643ef8419b72f66f85256485005505bc?OpenDocument

#1 - I created an action button that displays address picker and then calls agent:

Action Button:

tempnames := @PickList([Name]);

FIELD tempnames := tempnames; “”;

@PostedCommand(ToolsRunMacro]; “(NotifyTimeRange)”)

Agent:

Sub Initialize

Dim ws As New NotesUIWorkspace

Dim s As New NotesSession

Dim db As New NotesDatabase("","")

Dim doc As NotesDocument, cdoc As NotesDocument, invitedoc As NotesDocument



Dim uidoc As NotesUIDocument

Set uidoc = ws.CurrentDocument



Call db.OpenMail

Set doc = ws.CurrentDocument.Document

Set cdoc = db.CreateDocument



Dim unid As String

unid = cdoc.UniversalID



Dim d1 As NotesDateTime

Dim item As NotesItem

Set item = doc.GetFirstItem("StartDateTime")

Set d1 = item.DateTimeValue	

Set domDateTime = s.CreateDateTime("" & d1.DateOnly & " " & d1.TimeOnly)



Dim d2 As NotesDateTime

Set item = doc.GetFirstItem("EndDateTime")

Set d2 = item.DateTimeValue



'Names from Address Book

Dim sendTo As Variant

Dim tempnamesdoc As NotesDocument

Set tempnamesdoc = uidoc.Document

sendTo = tempnamesdoc.tempnames



Call cdoc.ReplaceItemValue("$NoPurge", d2)

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

Call cdoc.ReplaceItemValue("Chair", "")

Call cdoc.ReplaceItemValue("EndDateTime", d2)

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

Call cdoc.ReplaceItemValue("From", "")

Call cdoc.ReplaceItemValue("NoticeType", "I")

Call cdoc.ReplaceItemValue("OrgTable", "C0")	

Call cdoc.ReplaceItemValue("Principal", "")	

Call cdoc.ReplaceItemValue("RequiredAttendees", sendTo)	

Call cdoc.ReplaceItemValue("SendTo",sendTo)

Call cdoc.ReplaceItemValue("SequenceNum",1)

Call cdoc.ReplaceItemValue("StartDate",d1)	

Call cdoc.ReplaceItemValue("STARTDATETIME", d1)		

Call cdoc.ReplaceItemValue("_ViewIcon", 133)



Dim calendarBody As NotesRichTextItem

Set calendarBody = New NotesRichTextItem(cdoc, "Body")

cdoc.Subject = doc.Description(0) + " (Use Remove From Folder to remove from Inbox)"

Call calendarBody.AppendText(doc.Group(0) +" - "+ doc.Description(0))

Call calendarBody.AddNewLine(2)			

Call calendarBody.AppendText("Follow this link to view the event entry -> ")

Call calendarBody.AppendDocLink(doc, cdoc.Subject(0))



Call cdoc.Send(False)

End Sub

Subject: RE: LotusScript Calendar Agent Problem - My Solution

nice code but how about to reserve a meeting room resource? Any ideas?