• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:

Copy a document from a view from Database A to Database B

Hi Experts,
I need some assistance for the following:

I would like to schedule an agent that will run every 5 minutes and this agent will pick up all the documents from view named Cancelled from Database A
and copy it to Database B (database B is in a different server) and then delete the documents from the view Cancelled in database A.

Please advise.
thanks
Sri
0
sridevi911
Asked:
sridevi911
  • 6
  • 4
  • 3
1 Solution
 
p_parthaCommented:
Dim session As New notessession
      Dim db As notesdatabase
      Dim dest As notesdocument
      Dim doc As notesdocument
      Dim doc1 As notesdocument
      Set db = session.currentdatabase
      Set targetdb = session.getdatabase("","<yournsfname>")
      Dim view As notesview
set view = db.getview("cancelled")
set doc = view.getfirstdocument
while not doc is nothing
Call doc.CopyToDatabase( targetdb )
set doc= view.getnextdocument(doc)
wend
Set vc = view.AllEntries
Call vc.RemoveAll(True)
0
 
p_parthaCommented:
I didn't see that yoru database B is in other server, then it is not possible in R5, Try creating a replica in the same server and replicate with the above code

Partha
0
 
Sjef BosmanGroupware ConsultantCommented:
Forgive me please if I'm trespassing, but why do you want to do that? Are there many Cancelled documents? Isn't it enough to remove the Cancelled documents from all the views, by excluding them from the SELECT statement?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
p_parthaCommented:
In this TA Tresspassing is allowed and encouraged :)

Partha
0
 
Sjef BosmanGroupware ConsultantCommented:
I stepped on a few toes too many, some very sensitive ones probably, so I'm a little bit more careful now... Not too careful of course, for I like a firm discussion every now and then. :) And there are some people whose questions I do not respond to anymore... ;)

I just like to know if the suggested solution (the agent) is indeed the best answer to the problem, from a functionality perspective. I'd therefore love to see WHAT the problem is, so we can discuss that and then decide HOW it is best solved.
0
 
sridevi911Author Commented:
no the client wants it in a different archive database. so we should be storing the cancelled docs in the primary.

partha,

what do you mean by saying r5. this is not a UI Agent. This would run on the server and our server is 6.0.1 i guess.
so will this work.

please advise.
thanks
0
 
sridevi911Author Commented:
sorry correction.

we should NOT be storing the cancelled docs in the primary.
0
 
Sjef BosmanGroupware ConsultantCommented:
Don't understand. Why don't leave those cancelled documents for some time in the database? When they are cancelled, change their Formname or whatever, so nobody can see them. Or add a Readers-field with a pre-defined value. Then nobody else can see the document.

The agent could then run only once per day, which is a whole lot more efficient than an agent every 5 minutes. Partha's agent will do that just fine.
0
 
sridevi911Author Commented:
sjef. the client says he wants to see the cancelled for reference in a seperate db called archives.

so even if i make this dissapear in the primary db, i still have to copy the cancelled to the archives.

thanks . i'll try to use partha's code above.

0
 
sridevi911Author Commented:
the client dosen't want them to be stored in the primary db.
0
 
sridevi911Author Commented:
partha,

a little change to your code above.
what if i only want to copy and delete the selected document or documents only from database A to database B

Currently your code above works for all the docs. it copies all docs and deletes all docs. i only want to do that for selected ones.
thanks
0
 
p_parthaCommented:
Dim session As New notessession
     Dim db As notesdatabase
     Dim dest As notesdocument
     Dim doc As notesdocument
     Dim doc1 As notesdocument
     Set db = session.currentdatabase
     Set targetdb = session.getdatabase("","<yournsfname>")
     Dim doccoll As notesdocumentcollection
set doccoll = db.unprocesseddocuments
'set view = db.getview("cancelled")
set doc = doccoll.getfirstdocument
while not doc is nothing
Call doc.CopyToDatabase( targetdb )
set doc= doccoll.getnextdocument(doc)
wend
'Set vc = view.AllEntries
'Call vc.RemoveAll(True)
call doccoll.removeall(true)
0
 
sridevi911Author Commented:
super
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now