1
votes

I'm currently using the domino desginer 8.5.2 and I encountered a strange thing related to the notesdocument Created property.

I'm trying to create an agent in lotusscript that selects some documents based on their Created date.

I have the following test code where doc is a NotesDocument in a specific NotesDatabase:

If doc.Created < DateNumber(1951,1,1) Then
    Print "old"
End If

The issue is that there are no documents in the DB that are older than 2010 yet the code above Prints "old" for some documents (like 10 in 5k), but when I enter the debugging session and check the doc's Created property in the Variables window it's a normal date like 2012. 02. 03. or smth.

Another interesting note is that if I try to write the Created date into a csv file it's a nonsense date like 1896. 06. 20. but then again when I check the property while debugging it's completely normal.

Have you encountered this issue before? Or am I comparing dates in the wrong way?

----EDIT1------------

I oversimplified the question, I'm really sorry if it was misleading I can only humbly ask you to keep the ideas comming because solving this issue is crucial.

The agent in question does not process it's own documents, it's opening multiple databases on the server (a lot of ppl's mail databases) and processing documents (emails) by multiple conditions. What we actually do is this:

    strFileName = "D:\temp\log.csv"
    Set nStream = session.CreateStream()
    nStream.Open(strFileName)
    nStream.Truncate

    Dim deleteCutoffDate As New NotesDateTime("Today")
    Dim moveCutoffDate As New NotesDateTime("Today")
    Dim tmp As Integer
    tmp = settingsDto.GetDeleteOlderThanMonths()
    Call deleteCutoffDate.Adjustmonth((-1)*tmp, True)

    searchForm$ = {Form = "Memo" }
    Set doccol = db.Search(searchForm, Nothing, 0) 'db is an opened NotesDatabase
    Set doc = doccol.GetFirstDocument

    While Not doc Is Nothing 
        Dim nextDoc As NotesDocument
        Set nextDoc = doccol.Getnextdocument(doc)

        'Earlier condition we tried            
        'If doc.Created < deleteCutOffDate.Lslocaltime
        ' deleteCutoffDate is today - 3 years
        If (Fix( doc.Created ) < Fix( CDat(deleteCutoffDate.Dateonly))) Then

                    'Suggested solution to check dates
                    Dim longTemp As Long
                    longTemp = Fix( CDat(deleteCutoffDate.Dateonly))        'should be 36,647 (#days from Dec 30, 1899 to May 1, 2000) 
                    longTemp = Fix( doc.Created )     'check this number makes sense (see last line)!

                'This is only for logging, testing.
                Dim temp As String
                temp = Format( doc.Created, "yyyy-mm-dd")+";"+doc.Noteid+";"
                Call nStream.WriteText(temp,EOL_PLATFORM)


                '******* Processing logic goes here **********

        End If
        Set doc = nextDoc 
    Wend 
Call nStream.Close()

So the problem and the symptoms I saw so far:

Some documents (always the same) have weird Creation dates. Let's say we have 3 documents A, B, C.

When I write document A's Created property to csv it says 1899-12-30 when I check the debugger the doc.Created is 2015-01-06 which is the correct date but Fix( doc.Created ) is 0. This makes no sense. This sould not pass the if condition and be written into csv acording to Fix beeing 0 yet is does.

Document B's date is 1899 in csv, debugger says 2015-10-25, Fix( doc.Created ) reports the correct number BUT this document should not have gone through the If condition since the if only allows a pass for documents older than 3 years starting from today. So if i run the script on '18-02-07 documents created before 15-02-07 should pass the condition.

Document C's date is 4916-04-18 everything else is the same as above
These issues apper on multiple (but always on the same) documents. But these are not special documents or anyting they are simple emails

Another thing I noticed is if I run the script multiple times in a row (without debugging or interfering) sometimes the CSV reports the correct dates! For me this suggests some sort of a reference issue but at this point i'm not sure how the world works.

Note that there are no other processing logic is involved, all the logic inside the If condition have been commented out that manipulated the documents. Test database has been restored to it's original state

If you have any ideas please don't hold back I am stuck on this issue for days now.

Thanks

3
That is odd behavior. I certainly haven't seen it. According to the IBM Docs, you're comparing the dates correctly. That said, I gave up on .Created as a criteria a long time ago because if you copy/paste a old document (or if a replication goes awry), the new document gets a new Created date. I prefer to create my own "created" kind of date field, that way I have control over what it says and how it's stored.Duston
IIRC, there is a reserved field name - probably "$created", but my memory isn't 100% on that - that overrides the documents actual Created property and would be returned by NotesDocument.Created. I suggest having a look at the doc properties box and seeing if there is a $created value or anything else that looks like it might be overriding. My suspicion is that there is one, and that it has a bad value or the wrong data type,Richard Schwartz
@Duston Thanks i keep that in mind in the future however it's a rather large project and I don't have control over what fields are on the documentsViktor Kiss
@RichardSchwartz Thanks for the suggestion I haven't found any fields that looks suspiciousViktor Kiss

3 Answers

0
votes

It looks like what you are trying to do should work fine. I think the created date comes from a part of the doc universal id, so if that was set programatically it would be possible to see docs with creation dates that looked very old.

I would suggest trying the following to see if you can spot where the issue is

dim longTemp as long
dateTemp = cdat( "May 1, 2000" )
longTemp = Fix( dateTemp )        'should be 36,647 (#days from Dec 30, 1899 to May 1, 2000) 
longTemp = Fix( doc.Created )     'check this number makes sense (see last line)!
If doc.Created < dateTemp then
    print "old"
end if

Re writing doc.created to a csv file, I would suggest formatting it as text before writing, so

format( doc.created, "yyyy-mm-dd")   'or your preferred date format
0
votes

I give up. Time to punt and suggest workarounds! Might any of these work?

Workaround 1: Formulas

Instead of an if block, build the date criteria within the search formula for doccol. This is probably faster anyway.

    strFileName = "D:\temp\log.csv"
    Set nStream = session.CreateStream()
    nStream.Open(strFileName)
    nStream.Truncate

    Dim deleteCutoffDate As New NotesDateTime("Today")
    Dim moveCutoffDate As New NotesDateTime("Today")
    Dim tmp As Integer
    tmp = settingsDto.GetDeleteOlderThanMonths()
    Call deleteCutoffDate.Adjustmonth((-1)*tmp, True)

    searchForm$ = {Form = "Memo" & @Created < [} + deleteCutoffDate.LocalTime + {]} '<--- removed if block and put criteria checking here
    Set doccol = db.Search(searchForm, Nothing, 0) 'db is an opened NotesDatabase
    Set doc = doccol.GetFirstDocument

    While Not doc Is Nothing 
        Dim nextDoc As NotesDocument
        Set nextDoc = doccol.Getnextdocument(doc)

        'Earlier condition we tried            
        'If doc.Created < deleteCutOffDate.Lslocaltime
        ' deleteCutoffDate is today - 3 years
                    'Suggested solution to check dates
                    Dim longTemp As Long
                    longTemp = Fix( CDat(deleteCutoffDate.Dateonly))        'should be 36,647 (#days from Dec 30, 1899 to May 1, 2000) 
                    longTemp = Fix( doc.Created )     'check this number makes sense (see last line)!

                'This is only for logging, testing.
                Dim temp As String
                temp = Format( doc.Created, "yyyy-mm-dd")+";"+doc.Noteid+";"
                Call nStream.WriteText(temp,EOL_PLATFORM)


                '******* Processing logic goes here **********
        Set doc = nextDoc 
    Wend 
Call nStream.Close()

Workaround 2: Filter through NotesDateTime?

Maybe this would work?

    strFileName = "D:\temp\log.csv"
    Set nStream = session.CreateStream()
    nStream.Open(strFileName)
    nStream.Truncate

    Dim deleteCutoffDate As New NotesDateTime("Today")
    Dim moveCutoffDate As New NotesDateTime("Today")
    Dim createdDate As NotesDateTime '<----
    Dim tmp As Integer
    tmp = settingsDto.GetDeleteOlderThanMonths()
    Call deleteCutoffDate.Adjustmonth((-1)*tmp, True)
    Call deleteCutoffDate.SetAnyTime '<----

    searchForm$ = {Form = "Memo" }
    Set doccol = db.Search(searchForm, Nothing, 0) 'db is an opened NotesDatabase
    Set doc = doccol.GetFirstDocument

    While Not doc Is Nothing 
        Dim nextDoc As NotesDocument
        Set nextDoc = doccol.Getnextdocument(doc)



        'Earlier condition we tried            
        'If doc.Created < deleteCutOffDate.Lslocaltime
        ' deleteCutoffDate is today - 3 years

        'Your current condition
        'If (Fix( doc.Created ) < Fix( CDat(deleteCutoffDate.Dateonly))) Then

        Set createdDate = New NotesDateTime(doc.Created)         '<----
        Call createdDate.SetAnyTime                              '<----
        If createdDate.TimeDifference(deleteCutoffDate) < 0 Then '<----
                    'Suggested solution to check dates
                    Dim longTemp As Long
                    longTemp = Fix( CDat(deleteCutoffDate.Dateonly))        'should be 36,647 (#days from Dec 30, 1899 to May 1, 2000) 
                    longTemp = Fix( doc.Created )     'check this number makes sense (see last line)!

                'This is only for logging, testing.
                Dim temp As String
                temp = Format( doc.Created, "yyyy-mm-dd")+";"+doc.Noteid+";"
                Call nStream.WriteText(temp,EOL_PLATFORM)


                '******* Processing logic goes here **********

        End If
        Set doc = nextDoc 
    Wend 
Call nStream.Close()

Workaround 3: Sanity filter

Add a function that checks and uses @Formulas if LotusScript fails, because while slower, hopefully that works

Function fdtSaneDocCreated(doc As NotesDocument) As Variant 'Dateonly

    Const ciMinDate = 40179 'CLng(CDat("1/1/2010"))
    Const ciMaxDate = 51136 'CLng(CDat("1/1/2040"))

    fdtSaneDocCreated = doc.Created
    If fdtSaneDocCreated < ciMinDate Or fdtSaneDocCreated > ciMaxDate Then
        'This is slower, but AT LEAST IT WORKS! (... hopefully)

        Dim array As Variant
        array = Evaluate({@Created}, doc)
        fdtSaneDocCreated = array(0)

        If fdtSaneDocCreated < ciMinDate Or fdtSaneDocCreated > ciMaxDate Then
            Error 1, "This workaround doesn't work for " + doc.NotesURL
        End If
    End If
End Function

and then change your code by replacing doc.Created with fdtSaneDocCreated(doc)

0
votes

Sorry for the long silence I really needed to catch up with this project.

First of all thank you all for contributing to this thread all of your answers added a puzze piece to the picture.

So the problem was that the doc.Created reported wrong dates. Following your posts I red the following documentation.

http://www-01.ibm.com/support/docview.wss?uid=swg21111786

According to the link above a documents Created date is determined by the OID.

So there is this: http://www-12.lotus.com/ldd/doc/domino_notes/9.0/api90ug.nsf/85255d56004d2bfd85255b1800631684/00d000c1005800c985255e0e00726863?OpenDocument

This link explains how the OID works and how it should look.

I checked the OID with NotesPeek and bingo! OID should have contained a vaild date but instead It was complete gibberish like 9856.06.20. Sometimes the date part was simply missing, that's why I saw 1899.

The closing point of this issue was the following link which confirmed that this strange behavior is a bug of Notes 8.5.1

https://www-01.ibm.com/support/docview.wss?uid=swg1LO47325