Trouble saving LS created calendar entry

All,

I have script that creates an appointment on a calendar. It will fill in the start date, end date, and subject.

If I place the doc in edit mode, save and close. Then the entry is in my calendar (I have remmed out ’ that code below). If I Call doc.Save(True,True) without placing the entry in edit mode, the entry does not save. I have refreshed my calendar view to see if it is just a refresh issue but it was not there.

Here is my code:

Dim NotesSession As New NotesSession

Dim workspace As New NotesUIWorkspace

Dim Doc As NotesDocument

Dim db As NotesDatabase

Dim UIDoc As NotesUIDocument  

Dim CurDoc As NotesDocument

Set CurDoc = workspace.CurrentDocument.Document



Set db = NotesSession.GetDatabase("Edison/SEL",CurDoc.Calendar(0))

Set doc = db.CreateDocument

doc.form = "Appointment"

sd =CurDoc.SDate(0) 

ed =CurDoc.EDate(0) 

st =CurDoc.SDate_1(0) 

et =CurDoc.EDate_1(0) 

Set itemA = doc.ReplaceItemValue("Subject", "**APPROVED LEAVE**")

Set itemA = doc.ReplaceItemValue("Broadcast", "1")

Set itemA = doc.ReplaceItemValue("AppointmentType", "2")  

Set itemA = doc.ReplaceItemValue("Alarms", "0")  

Set itemA = doc.ReplaceItemValue("StartDateTime", Cdat(st))  

Set itemA = doc.ReplaceItemValue("EndDateTime", Cdat(et))  

Set itemA = doc.ReplaceItemValue("StartDate", Cdat(sd))  

Set itemA = doc.ReplaceItemValue("EndDate", Cdat(ed))  



doc.ExcludeFromView = "D"

’ Set UIDoc = Workspace.EditDocument(True,doc)

’ Call UIDoc.Save

’ Call UIDoc.Close

Call doc.ComputeWithForm(False,False)

Call doc.Save(True,True)	

At present this is in a button action, but I will eventually move it to an agent to run on the server so that the entry can be added to another’s calendar.

Thanks for any help,

Teri

Subject: Trouble saving LS created calendar entry

In the case of the UIDoc you’ve got an appointment document open - you set all the fields and save it.

In the case of the doc, you’re creating a new document (in the background). I suspect the document has been created but is not meeting the selection criteria to be displayed on the view you’re looking at. To test this, do a database properties before and note the number of documents. Then run the code and see if there is 1 more document.

Based on your code look at the meteing view and see if your appointments are there without dates and times.

I suspect you’re going to have problems with these lines:

Set itemA = doc.ReplaceItemValue("StartDateTime", Cdat(st))  

Set itemA = doc.ReplaceItemValue("EndDateTime", Cdat(et))  

Set itemA = doc.ReplaceItemValue("StartDate", Cdat(sd))  

Set itemA = doc.ReplaceItemValue("EndDate", Cdat(ed))  

You should set them to use NotesDateTime values. But let’s see if you’re actually creating a document first.

Subject: RE: Trouble saving LS created calendar entry

Stephen,

Looks like your correct on the date issue. The start date is showing up as: 04/01/2009 12:00:00 AM PDT

but the start date time is showing as: 12/30/1899 08:00:00 AM PST

Do I need to combine the date and time to show up in the StartDateTime??? Or what? Can you point me in the correct direction?

I have searched this forum, have downloaded and looked at the code in the Vacation db on Sandbox and noted that the code there does not set the date fields.

Thanks Teri

Subject: RE: Trouble saving LS created calendar entry

Teri,

Am sure the problem is with date value. Even i faced same problem while working on similar lines.

The solution that worked for me is, though the field is datetime, i passed it into new notesdatetime object & applied object.LSLocalTime

Cheers

~DPJ

Subject: RE: Trouble saving LS created calendar entry

Work with actual notesdatestime value. If you stuck with string, convert them…

t_str1 = |@TimeMerge(@TextToTime(“| & strDate & |”);@TextToTime(“| & MeetStartTime & |”);“| & TimeZone & |”)|

t_var1 = Evaluate( t_str1 )

t_str2 = |@TimeMerge(@TextToTime(“| & strDate & |”);@TextToTime(“| & MeetEndTime & |”);“| & TimeZone & |”)|

t_var2 = Evaluate( t_str2 )

Set startDateTime		= New NotesDateTime(t_var1(0))

Set startDateOnly		= New NotesDateTime(startDateTime.DateOnly)

Set startTimeOnly		= New NotesDateTime(startDateTime.TimeOnly)

Set endDateTime		= New NotesDateTime(t_var2(0))

Set endDateOnly		= New NotesDateTime(endDateTime.DateOnly)

Set endTimeOnly		= New NotesDateTime(endDateTime.TimeOnly)

As you’re working with a backend document in this case you can use the simple assignment to set the values:

Set doc.EndDate		= endDateOnly

Set doc.EndDateTime	= endDateTime

Set doc.EndTime		= endTimeOnly

Set doc.StartDate		= startDateOnly

Set doc.StartDateTime	= startDateTime

Set dpc.StartTime		= startTimeOnly

Subject: RE: Trouble saving LS created calendar entry

Stephen and DP,

Thanks for the suggestions, but I seem to be having the same issue. If I try to save the calendar entries without opening in edit mode first, then they do not show up on the calendar view, instead it shows up in the Calendar Entries View. If I do open the calendar in edit mode, then it shows up in the calendar view perfectly.

I have went through the document properties, and could not find the item that I am setting or not setting to get it to show up in the view.

Here is the code I am trying to use now.

Thanks for any help.

Teri:

Dim NotesSession As New NotesSession

Dim workspace As New NotesUIWorkspace

Dim Doc As NotesDocument

Dim db As NotesDatabase

Dim UIDoc As NotesUIDocument 

Dim CurDoc As NotesDocument

Set CurDoc = workspace.CurrentDocument.Document



Set db = NotesSession.GetDatabase("Edison/SEL",CurDoc.Calendar(0))

Set doc = db.CreateDocument

doc.form = "Appointment"

Set itemA = doc.ReplaceItemValue("Subject", "**APPROVED LEAVE**")

Set itemA = doc.ReplaceItemValue("Broadcast", "1")

Set itemA = doc.ReplaceItemValue("AppointmentType", "2") 

Set itemA = doc.ReplaceItemValue("Alarms", "0") 

Set itemA = doc.ReplaceItemValue("_ViewIcon", "9") 

Set itemA = doc.ReplaceItemValue("$PublicAccess", "1") 



'***Start Put in/changed per Stephen****************************************************

strDate = CurDoc.SDate(0)

strDate2 = CurDoc.EDate(0)

Const MeetStartTime = "8:00am" 

Const MeetEndTime = "8:00pm" 

Const TimeZone = "Z=5$DO=1$DL=3 2 1 11 1 1$ZX=28$ZN=Eastern"



t_str1 = |@TimeMerge(@TextToTime("| & strDate & |");@TextToTime("| & MeetStartTime & |");"| & TimeZone & |")|

t_var1 = Evaluate( t_str1 )

t_str2 = |@TimeMerge(@TextToTime("| & strDate2 & |");@TextToTime("| & MeetEndTime & |");"| & TimeZone & |")|

t_var2 = Evaluate( t_str2 ) 



Set startDateTime = New NotesDateTime(t_var1(0))

Set startDateOnly = New NotesDateTime(startDateTime.DateOnly)

Set startTimeOnly = New NotesDateTime(startDateTime.TimeOnly)

Set endDateTime = New NotesDateTime(t_var2(0))

Set endDateOnly = New NotesDateTime(endDateTime.DateOnly)

Set endTimeOnly = New NotesDateTime(endDateTime.TimeOnly)



Set doc.EndDate = endDateOnly

Set doc.EndDateTime = endDateTime

Set doc.EndTime = endTimeOnly

Set doc.StartDate = startDateOnly

Set doc.StartDateTime = startDateTime

Set doc.StartTime = startTimeOnly



'***End  Put in per Stephen****************************************************



doc.ExcludeFromView = "D"



'****IF I LEAVE THIS IN THEN ENTRIES WILL SHOW ON CALENDAR VIEW **************

’ Set UIDoc = Workspace.EditDocument(True,doc)

’ Call UIDoc.Save

’ Call UIDoc.Close

'***IF I LEAVE THIS PART IN THEN ENTRIES DO NOT SHOW ON CALENDAR VIEW,  SHOWS ON ALL CALENDAR ENTRIES VIEW******

Call doc.ComputeWithForm(False,False)

Call doc.Save(True,True)