DateTimeList: Writing via LotusScript

Does anyone know how to write a DateTime List via LotusScript? The best I am getting is a Text List with date values as strings. If I open the Notes Document and then resave, it will convert to Date/Time format as a list.

What I am trying to do is copy a number of documents (Appointments) to users mail files. These users exist in different time zones and the documents that were created were in the central time zone. The various date time fields have the appointments running from 12:00:00 AM to 11:59:00 PM. When a user from an earlier timezone gets them, they appear on the previous day.

I am getting the users zone from their mail server and I want to change the zone from CST to their zone.

As a simple test example, I have a form with 2 fields on it. List1 and List2. They are both multivalued DateTime fields. I manually enter the values in List1. Thru Script, I want to change the zone from CST to PST and write the new values to List2.

Here is the code.

Dim s As New NotesSession

Dim db As NotesDatabase

Dim newlist() As Variant  'have tried string too.

Dim newdate As NotesDateTime





Set db = s.CurrentDatabase

Dim c As NotesDocumentCollection

Set c = db.UnprocessedDocuments



If c.Count = 0 Then Exit Sub

Set doc = c.GetFirstDocument



For x = 1 To c.Count	

	Set item = doc.GetFirstItem("List1")

	If doc.HasItem("List2") Then Call doc.RemoveItem("List2")

	Forall y In item.values

		row = row + 1

		Redim Preserve newlist(row)

		'y is not returning the zone component, which is fine

		newlist(row) = y & " PST"

	End Forall

	Set item = doc.ReplaceItemValue("List2", newlist)	

	Call doc.Save(True, True)

	Set doc = c.GetNextDocument(doc)

Next

I have tried CDat() and NotesDateTime variants as well with no success.

I was hoping to find a special type, ie Set item = New NotesItem(field, value, DATETIME) but that animal does not exist.

I need to do this in script and not force all of the users to open each of the documents and resave. Too bad doc.ComputeWithForm does not do this for me either.

Thanks for any suggestions.

Subject: Use NotesDateRange? (WAS: DateTimeList: Writing via LotusScript)

Subject: RE: Use NotesDateRange? (WAS: DateTimeList: Writing via LotusScript)

All of the dates are not in a range, ie 11/10/2003 - 11/17/2003.

The list is more like:

11/10/2003

12/3/2003

12/6/2003

1/2/2004

1/31/2004

There could be upto 10 values in the list.

I didn’t see a way for a dateRange to deal with that. Am I missing something?

Subject: RE: Use NotesDateRange? (WAS: DateTimeList: Writing via LotusScript)

No, you’re not. An Array of NotesDateTimes will do the trick, though (in R5, you couldn’t populate a field with an array of NotesDateTime objects, but in ND6 it works like a charm – and you can use .SetAnyTime to chop the time off if necessary).

Subject: RE: Use NotesDateRange? (WAS: DateTimeList: Writing via LotusScript)

Stan,

Thanks for the direction. I did not realize with ND6 you can dim and array of NotesDateTime, hence my frustration with string and variant arrays. That worked slick.

Thanks!

Subject: RE: Use NotesDateRange? (WAS: DateTimeList: Writing via LotusScript)

Ah gotcha, sorry. If you write this new set of values to your document as a NotesItem, so long as you pass in the values as variants of a date-time type, this should ensure the resulting NotesItem is created as a date-time one. I think you can pass in an array of NotesDateTime objects even – I’d be surprised if that didn’t work.

Update: per Stan’s post, yes, you can do an array of NDT objects. I should replicate, read then post :wink:

Subject: Try…

Assuming that you are in the Central Time Zone when converting… For x = 1 To c.Count

	Set item = doc.GetFirstItem("List1")

	If doc.HasItem("List2") Then Call doc.RemoveItem("List2")

	row = 0 'Set initial value

	Redim newlist(Ubound(item.Values))

	Forall y In item.Values

		Set newdate = New NotesDateTime(y & " PST")

		newlist(row) = newdate.LSLocalTime

		row = row + 1

	End Forall

	Set item = doc.ReplaceItemValue("List2", newlist)	

	Call doc.Save(True, True)

	Set doc = c.GetNextDocument(doc)

Next

Subject: RE: Try…

Bill,

I am not having a problem getting/setting the values, but the issue is having the notes document save the field (List2) as a multivalued NotesDateTime. It is currently saving as a string TextList. Editing/Saving the notes document will convert the field type, but I didn’t want to have to force the user to open all of the documents for this to work. They need to be dateTime format show they will show on their calendar.

Any other ideas?

Thanks

Subject: LSLocaltime

Originally I had used dateTime.Localtime which created a STRING entry in the dateArray. Using the LS prefix correctly sets the type to a date. The field is populated correctly from the backend as date/time list.

For i=1 To multBy

Call dateTime.AdjustDay( Cint( howOften ) )Redim Preserve dateArray(Count)

dateArray(Count) = dateTime.LSLocalTime

Msgbox Typename(dateArray(Count) )

Count = Count+1

Next

doc.allMyDates = dateArray