Question about posting calendar entry

Hi

Is it possible to send an calendar entry and not display this entry in Inbox ?

I have a database in which when i create a document I must send an calendar entry to my user.

Subject: Question about posting calendar entry

Yes it is possible. I recently had the scenario where I needed to add a reminder to the Users Calendar and not have it appearv in the inbox, because if they deleted it, it would delete from the calendar as well. It would appear in the inbox if I mailed the document in the script.

So here is what I did:

Signing the Agent with an ID that has editor or higher access to their mail file (and it needs to be an agent so you can use the runonserver method), I ran the following code:

  1. This agent runs after creation or modification of documents I ran this in two steps for debugging purposes, which is why the agent is called for each document, which I would not normally do):

Dim session As New NotesSession

Dim db As NotesDatabase

Set db=session.CurrentDatabase

Dim view As NotesView

Set view=db.GetView(“luvaCalendarAdds”)

Dim vcol As NotesViewEntryCollection

Set vcol=view.GetAllEntriesByKey(“KEY”)

Dim entry As NotesViewEntry

Set entry=vcol.GetFirstEntry

Dim doc As NotesDocument

Dim agentAdd As NotesAgent

While Not (entry Is Nothing)

Set doc=Entry.Document

Set agentAdd=db.GetAgent

 ("(AddNewReminderToCalendar)")

If agentAdd.RunOnServer(doc.NoteID) = 0 Then

 Print "Agent ran",, "Success"

Else

 Print "Agent did not run",, "Failure"

End If

Set entry=vcol.GetNextEntry(entry)

Wend

  1. The agent called does this (at its core, other parts are not included because they are not relevant). It does it this way because if the fields were not set this way, they would not exist on the document unless the document was reopened physically and saved. doc.Computewithform would not cut it because it would fail validation and not save. :

Sub AddReminderToCalendar (session As

NotesSession, db As NotesDatabase, doc As

NotesDocument, strDateField As

String,strTimeField As String, strSubject As

String, strPeriod As String)

Messagebox “Starting AddReminder”

Dim strPeriodComb As String

If strPeriod=“start” Then

strPeriodComb=doc.AddToCalendarStart(0)

Else

strPeriodComb=doc.AddToCalendarEnd(0)

End If

If strPeriodComb <> “Yes” Then

Dim dbMail As notesdatabase

Dim doc2 As NotesDocument

Dim newdoc As notesdocument

Dim subj As Variant

Dim apptdatetime As Variant

Dim apptenddatetime As Variant

Dim note As NotesRichTextItem

'…set value of doc…

Dim username As New NotesName

 (doc.eqcoReserveForCompute(0))

Dim strUser As String

strUser = username.canonical

Dim strCat As String

strCat=“String”

Dim strcatConvert As String

strCatConvert=Format(strCat, “>”)

'Get a handle on the user’s home/mail server and mail file name from the ini fille

Dim server As String

Dim mailfile As String

If getMailfile(session, db, userName, server,

mailfile) Then

Messagebox "Gotmail File"

Print server

Print mailfile

'Open the user’s mail file and get the meetings view

Set dbMail = session.getdatabase

  (server$,mailfile$)

	

'Obtain values to be entered into the user's calendar 

		

Dim vApptDate As Variant

vApptDate=doc.GetItemValue(strDateField)

Dim appt_date As String

appt_date = vApptDate(0)



Dim vApptTime As Variant

vApptTime=doc.GetItemValue(strTimeField)

Dim appt_time As String

appt_time = vApptTime(0)

		

apptdatetime = appt_date & " " & appt_time

apptenddatetime = appt_date & " " &

   appt_time

		

'Create the calendar entry

If Not (dbMail Is Nothing) Then	

Set doc2 = dbMail.createdocument

doc2.Form = "Appointment"

doc2.From = strUser

doc2.Chair = strUser

doc2.AltChair = strUser

doc2.Principal = strUser

			doc2.AppointmentType = "4"

doc2.Subject = strSubject

doc2.Categories = strCat

			doc2.ScheduleSwitcher = "1"

doc2.OrgTable="C0"

			doc2.StartDateTime =Cdat(apptdatetime)

doc2.StartDate = Cdat(appt_date)

			doc2.EndDateTime = Cdat(apptenddatetime)

doc2.EndDate = Cdat(appt_date)

doc2.StartTime = Cdat(appt_time)

doc2.EndTime = Cdat(appt_time)

doc2.~_ViewIcon = 10

			doc2.CalendarDateTime = Cdat

     (apptdatetime)

						Dim rtNote As NotesRichTextItem

Set rtNote = New NotesRichTextItem ( 

      doc2, "Body" )

Call rtNote.AppendText( "Click here to 

      go to the reservation document==>>" )

Call rtNote.AddTab( 1 )

Call rtNote.AppendDocLink (doc,"")

Dim stringArray ( 1 To 2 ) As String

stringArray( 1 ) = "D"

stringArray( 2 ) = "A"

Call doc2.AppendItemValue

        ("ExcludeFromView",stringArray)

doc2.SequenceNum = 1

Call doc2.AppendItemValue

          ("$PublicAccess","1")

Call doc2.AppendItemValue("$Alarm", 1)

Call doc2.AppendItemValue

      ("$AlarmDescription", strSubject)

Call doc2.AppendItemValue

      ("$AlarmMemoOptions", "2")

Call doc2.AppendItemValue

      ("$AlarmOffset", -1440)		

Call doc2.AppendItemValue

      ("$AlarmSendTo", strUser)

Call doc2.AppendItemValue

      ("$AlarmSound", "chord")

Call doc2.AppendItemValue

      ("$AlarmUnit", "D")

Call doc2.AppendItemValue

      ("$AltPrincipal", strUser)

Call doc2.AppendItemValue("Alarms", "1")

Call doc2.AppendItemValue

      ("$BorderColor", "D2DCDC")

Call doc2.AppendItemValue

       ("$CSVersion", "2")

			

Dim strCSWISL (0 To 4) As String

strCSWISL(0)="$S:1"

strCSWISL(1)="$L:1"

strCSWISL(2)="$B:1"

strCSWISL(3)="$R:1"

strCSWISL(4)="$E:1"

Dim itemCSWISL As NotesItem

Set itemCSWISL = New NotesItem ( 

      doc2, "$CSWISL", strCSWISL )

	

    Call doc2.AppendItemValue

        ("$ExpandGroups", "3")

Call doc2.AppendItemValue

        ("$FromPreferredLanguage", "en-US")

Call doc2.AppendItemValue

        ("$HFFlags", "1")

Call doc2.AppendItemValue

        ("$LangChair", "")

Call doc2.AppendItemValue("$NoPurge", 

        Cdat(apptdatetime))

Call doc2.AppendItemValue

        ("$SMTPKeepNotesItem", "1")

			

Dim strWatched (0 To 4) As String

strWatched(0)="$S"

strWatched(1)="$L"

strWatched(2)="$B"

strWatched(3)="$R"

strWatched(4)="$E"

Call doc2.AppendItemValue

      ("$WatchedItems", strWatched)

			

Call doc2.AppendItemValue

      ("$BusyName", "")

Call doc2.save(True,False)

Call doc2.PutInFolder("$Alarms", True) 

			

If strPeriod="start" Then

      doc.CalStartUNID=Cstr

        (doc2.Universalid)			  doc.AddToCalendarStart="Yes"

Else

  doc.CalEndUNID=Cstr(doc2.Universalid)

  doc.AddToCalendarEnd="Yes"

End If

			

Call doc.save(True, False)

Print "An entry has been made in your 

      calendar for this appointment." 

Else

Print "Coud not Locate mail File"

end if

else

Messagebox "This entry has already been

   added to your calendar."

End If

End Sub

Subject: Thanks! I was stumped until I saw this.

http://www-10.lotus.com/ldd/nd6forum.nsf/DateAllThreadedweb/4e88f3cf261afcbc85256efd0076cf00?OpenDocument