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

Moving Documents from One Database to Another

Status
Not open for further replies.

IAGH

Technical User
Mar 11, 2003
4
0
0
GB
I have a database which is more or less a list of tasks to be done. In the database I have a checkbox field that when checked indicates that the task has been completed.

What I want to do is when the task (i.e. when the completed field is checked)the record/document is movedfrom the current database to another database/archive.

Can anyone think of an easy way to do this automatically?

Thanks in advance
 
Automatic means a scheduled agent. The easiest thing to do is write a daily LS agent that goes over all docs in a view that lists only completed docs and moves them.

Sample code for that would be like this :

Code:
dim session as new notessession
dim db as notesdatabase
dim arcdb as notesdatabase
dim view as notesview
dim doc as notesdocument
dim movedoc as notesdocument
dim flag as integer

set db = session.currentdatabase
set arcdb = session.getdatabase(db.server,<arcdb filepath>)
if arcdb.isopen then 'checks that the archive is available
set view = db.getview(<view name>)
set doc = view.getfirstdocument
do while not doc is nothing
set movedoc = doc.copytodatabase(arcdb)
flag = doc.remove(false)
delete movedoc
set doc = view.getfirstdocument
loop
end if

This code opens the current db, then opens the archive db and checks to see that it is available. If not, end of code (you can devise an error message here with Print, it writes to the server log database).
If all is well, the code goes on to open the view which lists all finished docs. Set the view up with the appropriate selection formula. Does wonders to save on coding for all docs in the database.
Once the first doc is loaded, the fun starts.
For each doc, a copy is created in the archive db.
Then the original is deleted. You can use flag to check if the deletion has been done correctly. If not, be aware that the code will once again load that doc to delete, so you need to think about what you can do (error message and exit the code, for example).
If all goes well, a new first document is loaded. This has to be done this way because the method getnextdocument has nothing to work on once the original is deleted. No problem, since the view updates automatically !
Once there are no more docs in the view, you're done.

All you need to do is copy the code to a new agent, set it up for running daily at 4 a.m., and make sure you have the right to run agents.

Good luck !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top