Replaceitemvalue in Calendar entry

If I run the agent manually it works fine; however, if the agents is saved and ran with the Server’s id as a scheduled agent, nothing happens. No errors. The values are not replaced. The Server has Manager access with all options, delete, etc.

Any suggestions?

'*****04/11 - CANCEL Vacation Day

Print "Running CANCEL Vacation Day"



On Error Goto ErrorHandler



Dim s As New NotesSession

Dim db As NotesDatabase

Dim maildb, maildb2, nabdb As NotesDatabase

Dim v, v2, v3, v4 As NotesView

Dim vc As NotesViewEntryCollection

Dim entry, entry1 As NotesViewEntry

Dim doc, vdoc, caldocm, vacationdoc As NotesDocument

Dim subjectitem As notesitem

Dim subject, InputValue As String



InputValue = "Vacation Cancelled"

InputValue2 = "Vacation Cancelled"



Dim dateTime As NotesDateTime

Dim dateTime2 As NotesDateTime

Dim icalendartime, icalendartime2 As New notesdatetime("")



'Set all variables in attempt to see why getting error

Dim vactype, vhours As String

Dim key, key2, FullKey As String

Dim sername, sername2 As String

Dim filename, filename2 As String



Set db = s.CurrentDatabase

Set v = db.GetView("(Cancelled)")

v.AutoUpdate = False

Set doc = v.GetFirstDocument



While Not (doc Is Nothing)		

	'Set variables

	vactype = doc.daytype(0)

	key = doc.dayname(0)

	keyLen = Len(key)

	dateoff = doc.vacdate(0)

	dateoffstring = Cstr(dateoff)

	key2 = doc.realmgrname(0)	

	

	'get the user's mail file

	sername = db.Server

	Set nabdb = s.GetDatabase(sername, "names.nsf")

	Set v2 = nabdb.GetView("($mailfile)")

	Set entry = v2.GetEntryByKey(key)

	

'****if entry no longer with company

	If Not entry Is Nothing Then

		filename = entry.ColumnValues(1)

	End If

%REM

'Open the user's mail file and remove entry

	Set maildb = s.GetDatabase(sername, filename)

	Set v4 = maildb.GetView("(CalSummary)")

	Set vacationdoc = v4.GetDocumentByKey (dateoffstring )

	

	'change entry to Public

	Dim pItem As NotesItem

	Set pitem = vacationdoc.ReplaceItemValue("$PublicAccess","1")

	

	While Not ( vacationdoc Is Nothing )

		Set appointmenttypeitem = vacationdoc.GetFirstItem("AppointmentType")

		appointmenttypevalues = appointmenttypeitem.Values(0)

		

		Set icalendartime = New NotesDateTime (vacationdoc.CalendarDateTime(0))

		calendartimedateonly = icalendartime.dateonly

		

		If calendartimedateonly <> dateoffstring Then 

			Goto LeaveHere

		End If

		If appointmenttypevalues = "2" Then

			

			Set subjectitem = vacationdoc.GetFirstItem("Subject")

			itemvalues = subjectitem.Values(0)

			result = Left$(itemvalues, 12)

			

			If result = "Vacation Day" Then

				Call vacationdoc.ReplaceItemValue ("Subject", InputValue)

				Call vacationdoc.Save(True, False)

			End If

			

		End If

		Set vacationdoc = v4.GetNextDocument(vacationdoc )

		

	Wend 

%ENDREM

	'get the manager's mailfile

	

	sername2 = db.Server

	Set nabdb = s.GetDatabase(sername2, "names.nsf")

	Set v3 = nabdb.GetView("($mailfile)")

	Set entry = v3.GetEntryByKey(key2)

	filename2 = entry.ColumnValues(1)

	

	'Open the manager's mail file and add entry

	Set maildb2 = s.GetDatabase(sername2, filename2)

	Set v3 = maildb2.GetView("(CalSummary)")

	

	'get entry

	'Set vc = v3.GetAllEntriesByKey(dateoffstring)

	'Dim entry6 As NotesViewEntry

	'Set entry6 = v3.GetEntryByKey(dateoffstring)

	'Set entry6 = vc.GetNthEntry(1)

	'columnvalue = entry6.ColumnValues(6)

	'Messagebox "Count: " & vc.Count

	'Call vc.DeleteEntry(entry6)

	'Messagebox "Count: " & vc.Count

	

	'get document

	Set vacationdoc2 = v3.GetDocumentByKey (dateoffstring )

	

	While Not ( vacationdoc2 Is Nothing )

		Set appointmenttypeitem2 = vacationdoc2.GetFirstItem("AppointmentType")

		appointmenttypevalues2 = appointmenttypeitem2.Values(0)

		

		Set icalendatetime2 = New NotesDateTime (vacationdoc2.CalendarDateTime(0))

		calendartimedateonly2 = icalendatetime2.dateonly

		

		If calendartimedateonly2 <> dateoffstring Then 

			Goto LeaveHere

		End If

		If appointmenttypevalues2 = "4" Then

			

			Set subjectitem2 = vacationdoc2.GetFirstItem("Subject")

			subjectitem2value = subjectitem2.values(0)

			

			SubjectLen = Left$(subjectitem2value, keyLen)

			If SubjectLen = key Then

				

				SubjectMid = Mid$(subjectitem2value, keyLen + 2, 8)

				

				If SubjectMid = "Vacation" Then

					Call vacationdoc2.ReplaceItemValue ("Subject", SubjectLen + " " + InputValue2)

					Call vacationdoc2.Save(True,False)

				End If

			End If

		End If

		Set vacationdoc2 = v3.GetNextDocument(vacationdoc2 )

		

	Wend 

%REM

		'*****added 02/16 to update the IS Planning Calendar

If dept = "MIS" Or Left$(dept,3) = "MIS" Then

	

		'Open the IS Planning Calendar and add entry

		'Set maildb = s.GetDatabase(sername2, filename2)

	Set maildb = s.GetDatabase("HQ1/McCoy", "mail/iplannin")

	Set caldoc = maildb.CreateDocument

	caldoc.Form = "Appointment"

	caldoc.Subject = key + " " + vactype + " Day" + " " + vhours + " Hours"

	caldoc.AppointmentType = "4"

	caldoc.StartDate = doc.vacdate(0)

	caldoc.EndDate = doc.vacdate(0)

	caldoc.StartTime = "08:00:00 AM"

	caldoc.EndTime = "05:00:00 PM"

	Dim Item3 As NotesItem

	Set item3 = caldoc.ReplaceItemValue("_ViewIcon", 10)

	Dim mItem3 As NotesItem

	Set mitem3 = caldoc.ReplaceItemValue("$MessageType","Not a Draft")

End If

		'*****end of 02/16 update

%END REM

'set the original doc so it disappears from the view

	doc.agent = "1"

	Call doc.Save(True, True)

	

	Set doc = v.GetNextDocument(doc )

Wend



Print "Completed CANCEL Vacation Day"



Exit Sub

ErrorHandler:

' Use the Err function to return the error number and 

 ' the Error$ function to return the error message.

Print "Error" & Str(Err) & ": " & Error$ 

Exit Sub

LeaveHere:

Print "Leave here..."

Exit Sub

End Sub

Subject: Replaceitemvalue in Calendar entry

Your description of what happens (“Nothing happens”) is imprecise. Does the agent log show the agent as having run? Does the message “Running CANCEL Vacation Day” appear on the server console/log?

I suspect that your use of Cstr to convert the date to a string is producing a date in a format that doesn’t match the string that appears in the view. Use the remote debugger, or put a print statement there to check it out.

Subject: RE: Replaceitemvalue in Calendar entry

Thanks for your response. The agent logs does show "Running CANCEL Vacation Day’ and also, “Completed CANCEL Vacation Day.” As I stated, the agent works as intended when ran manually, with or without the debugger, but when the agent runs as a scheduled agent, using the Server’s id, NOTHING happens. The Running and Completed print statements are entered in the log, but nothing. I need to open the client at the server console and debug the code using the Server’s id. For some reason, the server doesn’t appear to be able to change the values, but not sure why. Again, thanks for the response.