Search code examples
lotus-noteslotus-dominolotusscript

Lotus Domino (Lotusscript) : Dynamic lookup of document - View


I'm a beginner programmer of lotusscripting, and made a few basic codes on my own. Recently I've made a scheduled agent that copies documents in a view and move it to another database (archive db). But there is another enhancement that needs to be done, it's to make the location of the archive db dynamic. You can see on my code that the server/path&filename is hardcoded:

%REM
Agent Archive Kiosk Walk-In Test
Created Dec 11, 2015 by Daryl
Description: Comments for Agent
%END REM
Option Public
Option Declare

Sub Initialize
Dim s As New NotesSession
Dim db As NotesDatabase
Dim dbArchive As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim tmpDoc As NotesDocument
Dim docArchive As NotesDocument
Dim archiveDate As NotesDateTime
Dim createDate As NotesDateTime
Dim count As Integer
Dim serverName As String
Dim archiveName As String

Set db = s.Currentdatabase
Set archiveDate = New NotesDateTime("Today")
Call archiveDate.Adjustday(-30)

Set view = db.Getview("KWICompletedView")
view.Autoupdate = False

'Static declaration of database for archive
serverName = "SBYGAD61/SBYISDEV" 
archiveName = "reso\var\test\resovara.nsf" 
Set dbArchive = New NotesDatabase( serverName, archiveName )

If dbArchive Is Nothing Then 
    Print "Warning: unable to access archive database." 
Else
    count = 0
    Set doc = view.Getfirstdocument
    While Not(doc Is nothing)
        Set tmpDoc = view.Getnextdocument(doc)
        Set createDate = New NotesDateTime("")
        createDate.Localtime = doc.Created

        If archiveDate.Timedifference(createDate) > 0 Then
            Set docArchive = New NotesDocument(dbArchive)                   
            Call doc.Copyallitems(docArchive, True)
            Call docArchive.Save(True, True)
            'Call doc.Remove(True)
            count = count + 1
        End If

        Set doc = tmpDoc
    Wend 
    Print "Complete: "+Cstr( count )+" document(s) archived." 
    End If
End Sub

There's a view in my current database that contains the location of the archive dbs, yes, there are 3 archive dbs so I got really lost, I'm sorry. I need help on how will I actually get/set those documents as my archive location. Thanks!


Solution

  • You have some of the logic you need already. You need to get the view that contains the documents that have the locations of the archive DBs, correct? That would be done like this:

    Set viewArchiveInfo = db.Getview("View_With_Archive_Locations")
    Set firstArchiveInfoDoc = viewArchiveInfo.GetFirstDocument()
    serverName = firstArchiveInfoDoc.GetFirstItem("ArchiveServerName")(0)
    archiveName = firstArchiveInfoDoc.GetFirstItem("ArchiveName")(0)
    

    You could get the next documents if there are three different documents containing archive db information.

    You could also look into profile documents as a way to store the archive db information in an easier-to-access way.