Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LotusScript Archiving agent

Status
Not open for further replies.

DoctorGonzo

Programmer
Jan 23, 2004
48
GB
Hi all,

I am still trying to get to grips with LotusScript and would really appreciate some advice?

I am tyring to write an agent to run daily, which will check a date field (ExpiryDate), and if that date = today, then move (or copy then delete) these documents to database number 2.

I've been looking at this code, but am unsure about how to modify it really

Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.CurrentDatabase
Dim server As String
server = db.Server
Dim Db2 As New NotesDatabase(server,"CopyTest2.nsf")
Dim doc As NotesDocument
Dim view As NotesView
Set view = db.GetView("Testview")
Set doc = view.GetFirstDocument
Do Until doc Is Nothing

** I think this is where I put the IF EXPIRYDATE = TODAY code??? how to MOVE rather than COPY though?

Call doc.CopyToDatabase( Db2)

** OTHERWISE/ELSEIF....

Set doc=view.GetNextDocument(doc)
Loop

Please can someone kindly advise a novice?

Many many thanks,

Gonzo
 
Right, having looked over your code I think I can give you some pointers.

First, there is no method for moving a document. What you actually want to do is copy the document (you set that up fine), then mark it for later removal.

Once all documents have been checked, the ones that are marked will appear in a view you set up, and you can complete the script by purging those from the database.

So, how would I write this ? Like this :
Code:
dim Session as new notessession
dim db as notesdatabase
dim targetdb as notesdatabase
dim doc as notesdocument
dim olddoc as notesdocument
dim view as notesview
dim reftime as notesdatetime
dim doctime as notesdatetime

set db=session.currentdatabase
set targetdb=session.getdatabase(db.server,"CopyTest2.nsf")
if targetdb.isopen then
    set view=db.getview("Testview")
    set doc=view.getfirstdocument
    set refdate=new notesdatetime(now)
    do while not (doc is nothing)
        docdate=new notesdatetime(doc.expirydate(0))
        if docdate.lsgmttime >= refdate.lsgmttime then
            call doc.copytodatabase(targetdb)
            doc.deletemark="YES"
            call doc.save(false,false)
        end if
        delete docdate
        set olddoc=doc
        set doc=view.getnextdocument(olddoc)
    loop
    delete view
    set view=db.getview("DeleteDocs")
    set doc=view.getfirstdocument
    do while not (doc is nothing)
        call doc.remove(false)
        set doc=view.getfirstdocument
    loop
end if

Okay, now for a walkthrough.

First, I get the current and archive database like you do. As always, I test to make that the archive database is available before going on.
If it is, then I set up the reference variables I need, and I start the loop on the first document.
Why do I use a NotesDateTime object ? Because that is the only surefire way to easily compare date/time data in script.
If my expiry date is equal or more than today's date, the document needs to be dealt with.
If so, I copy the document to the archive db like you did, then I add a marker (anything goes here) and save the document (else the modification is lost).
Once that is done, I delete the current docdate object (to keep the memory clean), and go on to the next document in the view. By the way, I like to use an extra "olddoc" object to make the GetNextDocument clear - but that's just me.
Finally, when all docs have been dealt with, I purge the view object (Delete view) and call up another view.
This new view is one you need to add to your database. It should simply SELECT all documents that have your deletion marker. As soon as you save a document with the marker, it will show up in the view.
Thus, the code ends by getting the first document in the Delete view, deleting it (which makes the next one first), and starting over until nothing is left.

As you can see, you weren't very far off. Keep up the good work !

Pascal.
 
Many thanks Pascal, you certsainly went above and beyond there.

I now understand this process a lot better!

Gonzo :)
 
It is important to help point beginners in the right direction - that makes for less mistakes afterwards.

Glad to be of help,

Pascal.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top