Search DominoPower's 11,443 Lotus-related article archive 
Home
EasyPrint
News details Click here for the RSS feed's XML code. This is not a browser URL.
Articles-only Click here for the RSS feed's XML code. This is not a browser URL.
Twitter Feed Click here for the Twitter feed.
More fun with dates in LotusScript (continued)

While the application we were working on won't have such values, we were very leery of treating such a date as a null date. We needed to find a way around this issue. And this is what we came up with -- a sub to copy date values from one field to another, preserving null values along the way.

Let me call out a few items in this code.

1 Function CopyDate(fromdoc As NotesDocument, fromfieldname As String, todoc As notesdocument, tofieldname As String, debug as variant, nlog As NotesLog)
On Error Goto genericerrors
'Mick Moignard Oct 2004: copy date field from one doc to another and preserve null date values
'Also avoid any string conversions, so that there cannot be any problems with date format translations between DMY and MDY
5 'NotesDocument.CopyAllItems and NotesDocument.CopyToDatabase preserve items as is.

If fromdoc.HasItem(fromfieldname) Then
Dim dt As notesitem
Set dt = fromdoc.GetFirstItem(fromfieldname)
10 If dt.Text = "" Then 'genuinely null date field, or a text field with no value
Dim ndt As New NotesDateTime(Today)
Call ndt.setanydate
Call ndt.setanytime
Call todoc.ReplaceItemValue(tofieldname, ndt)
15 Else
Call todoc.ReplaceItemValue(tofieldname, dt)
End If
Else
If debug Then Call nlog.LogError(Err,"CopyDate - From document does not have field specified. " & _ "
20 Fieldname = " & fromfieldname & ", Doc = " & fromdoc.UniversalID)
End If

Exit Function 'skip the error block
genericerrors:
25 Call nlog.LogError(Err,"CopyDate - " & Error$ & " - " & Cstr(Erl)& ", Doc = " & fromdoc.UniversalID)
End Function

Lines 1, 19, and 25 show how we've managed debugging and error reporting in the whole of the code. We use a NotesLog to report activity and errors, and can turn on and off debugging reporting by use of the debug variant, which is also passed to all subs and functions in the application.

Lines 2 and 24/25 show how we report errors in every sub and function. It's very important in an application of any size to ensure that you have decent error trapping and reporting. 'Script makes this pretty easy, so there really is no excuse.

However, none of these are the problem we're trying to solve. That starts in line 1, where we pass in the name of the field to be copied, the document that contains the field, and the field name and document to be copied to.

The work starts in line 7 with some defensive code that checks to ensure the field we're to work on actually exists in the document passed. If so, we get it into a NotesItem. In line 10, we look to see if that NotesItem has a null value, and we do that by examining its text value, looking for "".

If it's null, we then create a new datetime field and set it to an all-null value in lines 12 and 13, with NotesDateTime.SetAnyDate and SetAnyTime, and write the results back to the new field in the destination document in line 14. Line 16 merely copies the non-null date/time to the new document.

And with this, our problems with rogue dates of 31/12/1899 disappeared. Whew.

Mick Moignard has been working and traveling with Lotus Notes since Release 2.0 in 1991. Mick is a DominoPower Senior Technical Editor and a Principal CLP with Unipart Expert Practices, a Lotus Advanced Partner in the UK. If you want to discuss anything to do with this article, or indeed anything else to do with Notes and Domino, contact Mick at Mick_Moignard@unipart.co.uk. Unipart Expert Practices will also happily discuss any opportunities you may have with any Notes and Domino application development or infrastructure projects you need help with. Unipart Expert Practices can be found at http://www.unipartep.com.


« Previous  ·  1  ·  2  ·  3
Other articles you might like
Home > Lotus Technologies > LotusScript (64 articles)
   When the debugger won't debug hidden code that isn't hidden
   What to do if the LotusScript debugger won't single-step over code
   Little known traps about Lotus Notes fields
Get Weekly Email Updates
Subscribe to our regular weekly email newsletter. It's packed with tips, reviews, deep analysis, and the latest news.
 
Recent DominoPower Articles
Syncing Notes with Android phones
Application development, William Shatner, and the origin of the universe
Learn Domino Designer 8.5 for free
The (near) future of Sametime, Quickr, Connections, and Symphony
Inside the IBM Innovations lab
Lotusphere 2010: Hot fixes and cool news for Notes, Domino, and LotusLive
Lotusphere 2010: mobility and collaboration
Latest Lotus Headlines
Xpages not loading? JVM errors? - Solution
How to implement an iCalendar feed into your Notes calendar with XPages
DWA Hotfixes for Domino 8.5.1FP1 - A Gotcha
IBM Adds DB2 to Lotus Foundations SMB Package
SNTT : XPages onclick Ghosts in the machine
Ports used by Lotus Sametime 8.5 servers
Exploring a Domino Date Bug
>> Read all the news
More from the ZATZ journals
Computing Unplugged: Online safety for virtual learning
David Gewirtz Online: CNN commentary and analysis
OutlookPower: Seek and find: Strategies to locate filed-away emails fast
-- Advertisement --

Find unused Lotus Notes groups and clean up your address book
Have you ever wanted to get rid of old Lotus Notes groups that were cluttering up your address book, but you weren't sure if they were used? Find Unused Groups can help.

Find Unused Groups will check your ACL, mail, multi purpose and server groups to help you determine if they are used, and who uses them.

Learn how to easily clean up your address book.

-- Advertisement --

Mark your calendar for in-depth Lotus training, May 12-14, Boston
Join experts and peers May 12-14 in Boston for educational and networking events that deliver real-world Lotus training so you can increase productivity and efficiency in your company, advance your skills, and squeeze the most from your current environment. One registration gets you into THE VIEW's Admin2010 and Lotus Developer2010.

Register by April 10 to save $200.
ZATZ Home  ·  News  ·  Back Issues  ·  Credits/Trademarks ·  Link To Us
Copyright © 1998-2010, ZATZ Publishing. All rights reserved worldwide.
Editor's Login