Link to home
Start Free TrialLog in
Avatar of Rossco111500
Rossco111500

asked on

Notes 6.0.3 Archiving agent.

PLEASE.
I would like an agent that can loop throught the mail folder grab the first dB, get all the documents AND ALL folders, and copy documents to correct folder to correct database. This agent will loop through many databases in the mail folder.... SEE CODE.


 I have seen many posting's of this, but none of which provide a solution.

So far I have.... IMPORTANT, I WANT TO MOVE THE DOCUMENTS TO THE CORRECT FOLDERS.


Sub Initialize
      
      Dim session As New NotesSession
      Dim archiveDb As NotesDatabase
      Dim collection As NotesDocumentCollection
      Dim doc As NotesDocument
                                    
      Dim dbdir As New NotesDbDirectory("App01")
      Dim db As NotesDatabase
      
      Set db = dbdir.GetFirstDatabase(DATABASE)
      
      Do While Not(db Is Nothing)
            ' Check Filepath contains mail!
            If Instr(db.FilePath, "mail\") <> 0 Then
                  
                  
                  Call db.Open( "", "" )
 
                                      '///////////////////////////////////////////////////////////////////////////////
                  'Set archiveDb = NotesDatabase( "", "" )
                  
                  Dim archiveServer As String      
                  Dim archiveFile As String
                  archiveServer$ = "App01"
                  archiveFile$ = "archive\a_"+db.FileName
                  
                  Set archiveDb = db.CreateCopy( archiveServer$, archiveFile$ )
                  
                  Set collection = db.AllDocuments
                  Set doc = collection.GetFirstDocument()
                  While Not(doc Is Nothing)
                                 '////////////////////////// CONDITION////////////////////
                                 'If ( doc.Created < Datenumber( 2003, 01, 01 ) ) Then
                             'Copy all Documents to TARGET
                                       'Call doc.CopyToDatabase( archiveDb )
                                       'Set doc = collection.GetNextDocument(doc)
                                       'End If      
                                  '////////////////////////////////////////////////////////EOC
                        Call doc.CopyToDatabase( archiveDb )
                        Set doc = collection.GetNextDocument(doc)
                  Wend
                                      '/////////////////////////////////////////////////////////////////////////////////
                            'Continue to loop through Db's
                  
                                              'Call MarkDocumentsForArchive(db, doc)
            End If
            
            Set db = dbdir.GetNextDatabase
            
      'Wend
      Loop
      
      
End Sub

Kind regards,

Ross
Avatar of SysExpert
SysExpert
Flag of Israel image

So it looks like you almost have it.

What is the problem ?

Also, why not use the built in archiving of R6 ?

I hope this helps !
Avatar of Rossco111500
Rossco111500

ASKER

The documents are not copied to the folders, they get copied to the "All Documents' view only. How do I maintain the same document\folder relationship?
.........Also, why not use the built in archiving of R6 ?

That's not a solution at this time unfortunately . What I really need is the code to maintain mail\folder relationship.
those documents will be archived to the same folders if the original docs are in the same order...
Are you suggesting I loop through each individual folder first get a collection, Copy to Archive then loop for all other folders\views in database.


From my code you will notice that I get a collection of all docs in DB....

Set collection = db.AllDocuments
Set doc = collection.GetFirstDocument()

and copy to databse indidually unitl I finished going through the document collection.


SHOULD I

Forall view In db.views

Set collection = db.AllDocuments
            Set doc = collection.GetFirstDocument()
            
            
            If (view.Isfolder) Then
                  Set doc = view.GetFirstDocument
                  While Not (doc Is Nothing)
                        Call doc.CopyToDatabase( archiveDb )
                        Set doc = collection.GetNextDocument(doc)
                  Wend
            End If
      Wend
             
 
I need to leave the office right now, will pick up on this first thing in morning!
Cheers ALL.
Use the PutInFolder method in the new database. To find out what folders the document appears in, use the FolderReferences property of a document. Lukcily for you, the mail template already seems to contain the 2 views necessary to make folder references available. Furthermore, the database should be set up to maintain folder references, which you can check by verifying the FolderReferencesEnabled property of the database. If not set, it can enabled by setting that property to True.
Sounds perfect, but silly question.. If I use putinfolder how do I copy it into the new database? ex.

ref = doc.FolderReferences
Messagebox ref

'NEW METHOD
Call doc.PutInFolder( ref )

'OLD METHOD
'Call doc.CopyToDatabase( archiveDb )

Set doc = view.GetNextDocument(doc)

Please supply helpful code if possible. I'm running out of time. Today's the last day on this until I have to go onto some other new challenge.

Thank you again.

> Please supply helpful code if possible.
May I reverse your question? Can you supply your code, for me to give some advice? We all have our own challenges but writing complete code usually is not one of them. What do you have right now?

To copy a document to another database, use
     Set newdoc= doc.CopyToDatabase(targetdatabase)
Sub Initialize
      Dim session As New NotesSession
      Dim archiveDb As NotesDatabase
      Dim collection As NotesDocumentCollection
      Dim doc As NotesDocument
      Dim ref As String
      Dim dbdir As New NotesDbDirectory("App01")
      Dim db As NotesDatabase
      Set db = dbdir.GetFirstDatabase(DATABASE)
      
      Do While Not(db Is Nothing)
            ' Check Filepath contains mail!
            If Instr(db.FilePath, "mail\") <> 0 Then
                  Call db.Open( "", "" )
                  If(db.FolderReferencesEnabled) Then
                        Messagebox "Folder References enabled"
                  Else
                        Messagebox "Folder References are not enabled"
                        Messagebox "Enabling Folder References"
                        db.FolderReferencesEnabled = True
                  End If
                  db.FolderReferencesEnabled = True
                  
                  Dim archiveServer As String      
                  Dim archiveFile As String
                  
                  archiveServer$ = "App01"
                  archiveFile$ = "archive\a_"+db.FileName
                  
                  Set archiveDb = db.CreateCopy( archiveServer$, archiveFile$ )
                  
                  Forall view In db.views
                        
                        Set collection = db.AllDocuments
                        Set doc = collection.GetFirstDocument()
                        
                        If (view.Isfolder) Then
                              Set doc = view.GetFirstDocument
                              While Not (doc Is Nothing)
                                    'If ( doc.Created < Datenumber( 2003, 01, 01 ) ) Then                                    
                                    'SOLUTION... I MAY REQUIRE TO USE THIS
                                    'We need to get the folder reference here!!!
                                    
                                    ref = doc.FolderReferences
                                    Messagebox "Subject : " &  ref
                                    
                                  ' THE DOCUMENT IS TO BE PLACED IN THE NEW DATABASE IN THE CORRECT FOLDER
                                    Call doc.PutInFolder( ref )
                                    
                                    'CopyToDatabase is NO good since it doesn't copy to folder in new database
                                    'Call doc.CopyToDatabase( archiveDb )
                                   'End If
                                    
                                    Set doc = view.GetNextDocument(doc)
                              Wend
                        End If
                        
                  End Forall
                  
            End If
            
            Set db = dbdir.GetNextDatabase
            
      Loop
      
      
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Sjef Bosman
Sjef Bosman
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
All points are valid.... including the "Is set twice, is it supposed to stick better then? ;)"... Yeh, I'm paranoid now! :-D


I'll tidy it all up and give it one more shot, but I'm thinking.....Oh know not again I hear you say......!


Do the documents have to be put into folders after the folder reference is enabled... If so (surely), then perhaps I need to put the documents into the folders after the folders references were enabled, because only then would they have the $FolderInfo!


Cheers

Ross
Lety me explain (oh not again!) how things are supposed to be done:
- you open a database
- you get documents from the database
- for each document, you get the folders it is in (hence the FolderReferences)
- then copy the document to the new database
- then set the folders the document is to appear in

The folder reference should therefore work on the OLD database.

Makes sense?

PS I'm only playing the piano, so don't shoot me when you find out that I've never written this song myself...
Thank's for all your efforts.

As for the points you get them all, despite the fact I was never far away. It was only the folder reference that eluded me. The solution is correct, but my point regarding the $FolderInfo is indeed pertinent to this topic, and to anyone else wishing to benefit from this lesson.


Thank you again.
Kind regards,

Ross
I thank you, sir!

You were close indeed with your code. You might have presented a design, see in my previous comment, for it would have made looking for the problem (or misconception in this case, if I may say so) so much easier. Reading code and reverse designing is a tedious job, which needs sometimes a lot of guesswork. That might be another reason why your question didn't get a large audience. Next time better. ;)

But you're right: handling folders in Notes is not very clear, as are many other things...

Sjef