PermaLink Creating a multi-value date field via Lotusscript01/23/2006
Lotusscript
Working with an existing multi-value field is challenging enough. But what if the multi-value field doesn't exist yet? For example, you're creating a new Notes document via the back-end classes, and one of the fields needs to contain multiple-values. Worse yet, the field needs to contain Date/Time values.

One problem with working with Date/Time fields via the back-end is that unless you're careful, you'll end up with values that include midnight, like this:

1/30/2006 12:00:00 AM
2/15/2006 12:00:00 AM
2/30/2006 12:00:00 AM

In some situations, it may not matter if the field values include the bogus midnight time. These values can cause problems with documents that are displayed in a calendar view. Personally, I hate sloppy coding. Side effects like this must be corrected, to keep Notes applications from being jettisoned to the Island of Misfit Apps.

For an example of how to create a multi-value date field without midnight times, click on the Read More link below...
The first thing you need to do is declare an array of type NotesDateTime. If you're array is a Variant, you're Date/Time values will be stored in the array, but when you replace the item's value with that array, your NotesItem will contain null.

The following code creates an array of dates. It starts with the date contained in a field in a Notes document, creates an array of NotesDateTime objects based on that date, then creates a new field in the document by replacing its value with the NotesDateTime object array.
Dim doc as NotesDocument Dim newDate as NotesDateTime Dim dates () As NotesDateTime Dim numValues as Integer Dim i as Integer Set newDate = New NotesDateTime ( cstr ( doc.StartDate (0) ) ) Call newDate.SetAnyTime numValues = 5 '-- or some other calculated value Redim Preserve dates ( numValues - 1 ) For i = 0 To ( ubound ( dates ) ) Set dates (i) = New NotesDateTime ( newDate.DateOnly ) Call dates (i).SetAnyTime '-- this is key to getting rid of the midnight time newDate.AdjustDay (1) Next Call doc.ReplaceItemValue ( "StartDates", dates )
This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.

See? Nothing too it.
Comments :v

1. Eric Rehnke05/10/2006 06:49:19 PM


You can't imagine how much time we have spent trying to make this work from the back-end classes. This solution is so elegant and works perfectly! I want to thank you for your effort here!!! The Notes documentation on .SetAnyTime suck as is typical for Notes documentation.

This is GREAT!!!! Lot's of others have been trying to achieve this as witnessed by the amount of traffic on the Notes forums.

Thanks again!!!




2. Randy01/04/2007 01:53:42 PM


Thank you!!
I have been struggling with dates continually getting changed to string format after I manipulated them in LS. Using the code above as an example I was finally able to get my dates to stay as a date/time format. The only hint in the documentation regarding SetAnyTime was that once done, field cannont be converted to text.




3. Manu Vermeyen06/18/2009 09:34:55 AM


Yup, a lifesaver! thank you very much. I looked for this solution for a while!




Credits
NuTechs Powered by Domino
Search
Calendar
February 2012
Su
Mo
Tu
We
Th
Fr
Sa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Monthly Archive
Get Real, Detroit!
Real Detroit Weekly
SWARM
Service
With
A
Rapid
Motion


-- old Rally's Hamburgers credo
Lotus Domino ND6 RSS News Feed RSS Comments Feed Podcast Feed Geo URL netcraft RSS Validator Lotus Geek Chris. A. Brandlehner Open Notes Picture Database OpenNTF CoComment Integrated BlogSphere
By Category
The BlogRoll
About
Contact Me
Contact me, Michael Sobczak, using this e-mail address:

my first initial my last name at Yahoo dot com
Recent Entries
No Recent Blogs
Powered by
Blogsphere