Lotus Domino: Create import log

2019-08-28 13:47发布

I have two databases: one holds the employee summary info, and the other one holds the serial number of the employee. On the database1, I have this agent that lets you import text file which contains updated records of the employee. But, In order for this agent to import a text file records successfully, the text file to be import must have a serial number record same as on the database2. It's working by the way, but I need to create a log when importing, still got no idea on how to resolve this. The logs(date imported, success and fail file imported) must be viewed on the fields. Can you help me out? Here's my code:

LoadAPMSAWDdoc

Sub LoadAPMSAWDdoc(Rname As Variant, directory As Variant, Datef As Variant)
Dim session As New NotesSession
Dim Tdoc As NotesDocumentCollection
Dim dateTime As New NotesDateTime ("01/01/2000")
'12/20/2005
Dim LocView As notesview
Dim LocDoc As NotesDocument
Dim subsidiary As String
Print "Loading APMSAWD - Award Information"

Set cdb = Session.CurrentDatabase
'12/20/2005
'StaffServerName = cdb.Server 
Set LocView = cdb.GetView("LsvLocationProfile")
'02/07/2006
'Set LocDoc = LocView.getdocumentbykey(cdb.Server)
Set LocDoc = LocView.getfirstdocument
StaffServerName = LocDoc.z_ExtServer(0)

 'SearchFormula$ = "Select Form = ""dfAward""  & @Date(s_Created) != @Date(@Today) "


If (ibmmy = True) And (ibmgdc = True) Then
SearchFormula$ = "Select Form = ""dfAward""  "
ElseIf  (ibmmy = True) Then 
SearchFormula$ = "Select Form = ""dfAward"" & I_GDCEmployee = ""IBM MY""" 
Else 
SearchFormula$ = "Select Form = ""dfAward"" & I_GDCEmployee = ""IBM GDC""" 
End If

Set Tdoc = cdb.Search( SearchFormula$, DateTime, 0 )  

If Tdoc.Count <> 0 Then
    Call Tdoc.RemoveAll(True)          
End If

 'Get an unused file number
file_no% = Freefile()
Open (Trim(directory + "apmsawd.txt")) For Input As file_no%      

Set db = Session.CurrentDatabase

Select Case Datef
Case "DMY" : Cdatf = "dd/mm/yyyy"
Case "MDY" : Cdatf = "mm/dd/yyyy"
Case "YMD" : Cdatf = "yyyy/mm/dd"
Case Else : 
    Print "LoadAPMSAWDdoc - Unknown system date format"          
    Exit Sub
End Select

Do While Not Eof(file_no%)
    Line Input #file_no%, tmp

    SerialNo = Trim$(Mid$(tmp,1,6))

    AB = 0
    For i = 29 To 0 Step -1               
        x1 = 8 + (i * 50)
        x2 = 11 + (i * 50)
        x3 = 41 + (i * 50)
        x4 = 49 + (i * 50)

        temp = Strconv(Trim$(Mid$(tmp,x2,30)),3)
        If temp <> "" Then
            Redim Preserve ACode(AB)
            Redim Preserve ADes(AB)
            Redim Preserve ADate(AB)
            Redim Preserve AAmt(AB)
            Acode(AB) = Trim$(Mid$(tmp,x1,3))
            ADes(AB) = temp
            If Trim$(Mid$(tmp,x3,8)) <> "" Then
                AD1 = Setdate(Trim$(Mid$(tmp,x3,8)), "mm/dd/yy", Datef)               
                ADate(AB) = Cdat(Format(AD1, Cdatf))
                     'Datenumber ( Val(Trim$(Mid$(tmp,x3+6,2))) , Val(Trim$(Mid$(tmp,x3+3,2))) , Val(Trim$(Mid$(tmp,x3,2))) )
            Else
                ADate(AB) = Null
            End If
            AAmt(AB) = Val(Trim$(Mid$(tmp,x4,9)))
            AB = AB + 1
        Else 
            Exit For
        End If
    Next

    subsidiary = Filter(CStr(SerialNo))
    If (subsidiary = "AMY" And ammmy = True) Or (subsidiary  = "ADC" And aaadc = True) Then

    Set doc = New NotesDocument(db)
    doc.Form = "dfAward"
    doc.E_StaffSerialNo = SerialNo
    doc.I_GDCEmployee = subsidiary
    If AB = 0 And Trim$(Mid$(tmp,1461,30))  = "" Then
        Redim Preserve ACode(AB)
        Redim Preserve ADes(AB)
        Redim Preserve ADate(AB)
        Redim Preserve AAmt(AB)
        ACode(0) = ""
        ADes(0) = ""
        ADate(0) = Null
        AAmt(0) = Null
    End If
    doc.E_AwardType = ADes
    doc.E_AwardDate = ADate
    doc.E_AwardAmt = AAmt
    doc.G_AuthorDisp = Rname
    doc.s_created = Now
    Call doc.Save (True, True)

    End If
Loop

Close file_no% 
Print "Award information imported"

End Sub

I'm sorry if I only posted some functions coz my code is too long and can't fit here.

1条回答
霸刀☆藐视天下
2楼-- · 2019-08-28 13:56

First of all: It is VERY bad practice, to permanently delete all documents that match a search criteria just to directly afterwards add them back.

Deletion stubs will explode and this database will become slower and slower and at some point will not be usable anymore.

Better build a key to identify the document, get the document using the key and then update if necessary...

I usually build a list with all keys / unids (or documents, if there are not to much of them) and remove any document found in the "source" (text document in your case) from that list after processing.

Any document left in the list after running through the import file can be deleted...

Dim lstrUnids List as String

Set doc = Tdoc.GetFirstDocument()
While not doc is Nothing
    lstrUnids( doc.E_StaffSerialNo(0) ) = doc.UniversalID
    set doc = TDoc.GetNextDocument(doc)
Wend

But now back to your Question:

To write a simple Log you can use the NotesLog- Class. You can either log to a database (Template: Agent Log ), log to a mail or log to the Agents log (complicated to read) or even to a file.

Just do it like this:

Dim agLog as New NotesLog( "MyImportLog" )
Call agLog.OpenNotesLog( Server , logdbPath )
...
Call agLog.LogMessage( "Award information imported" )
...
Call agLog.Close() 'IMPORTANT !!!!
查看更多
登录 后发表回答