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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Archiving documents with a shceduled LS agent!

Status
Not open for further replies.

DoctorGonzo

Programmer
Jan 23, 2004
48
0
0
GB
Hi all,

I'm trying (without any success) to write a Lotusscript scheduled agent to loop through my ALLDOCUMENTS view, setting the ARCHIVE field to "Y" for documents older than 6 months, and permanently deleting documents older than 12 months.

Can anyone help? I've been looking at NOTESDOCUMENT class, but I don't think it's the correct one. can anyone provide a hint or 2?

Many thanks as always!

Gonzo
 
You're on the right track with NotesDocument. This is how it could work :
Code:
[COLOR=green]'step 1[/color]
dim session as new notessession
dim db as notesdatabase
dim view as notesview
dim doc as notesdocument
dim olddoc as notesdocument
dim delflag as boolean
dim movtype as integer

[COLOR=green]'step 2[/color]
set db = session.currentdatabase
dim view = db.getview("($All)")
dim doc = view.getfirstdocument
do while not(doc is nothing)
    [COLOR=green]'step 3[/color]
    delflag = false
    movtype = checkdate(doc)
    if movtype = 1 then
        delflag = true
    else
        if movtype = 2 then
            doc.archive = "Y"
            call doc.save(false,false,false)
        end if
    end if
    [COLOR=green]'step 4[/color]
    set olddoc = doc
    set doc = view.getnextdocument(olddoc)
    if delflag then
        call olddoc.remove(false)
    else
        delete olddoc
    end if
loop
So what is going on here ?
I've divided the code into steps. Let's walk through them.

Step 1 : Declarations. Apart from the indispensable, you will notice that I have added a boolean flag and an integer. We will be using those later.
Step 2 : Setting up the objects and initialising the loop with the first doc in the view.
Step 3 : Gets interesting here. In this step I first set the deletion flag to false because we are starting the analysis of a new document. Then I call upon a function to check which operation I wish to do on the current document. I have left that function for you to write ;-).
Once we have the result of the function (1 = delete, 2 = archive, anything else is ignore), we can then act upon the result obtained, which is done in the test area.
Step 4 : Wrapping up by getting the next document in the view, and using the flag to check if the old one is to be removed.

For the checkdate function, do not forget that date/time comparisons in LScript are best done with the NotesDateTime object.

Have fun !

Pascal.
 
Many thanks again Pascal!

I'll let you know how I get on.

Gonzo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top