Move folders from one Notes database to another using a LotusScript agent

SearchDomino.com member Marko Bonaci provides a LotusScript agent that will move folders from your current Notes/Domino database to another that you specify.

VIEW MEMBER FEEDACK TO THIS TIP

When you run the LotusScript code below, it will ask you which folders you want to move from a current Notes/Domino database and to which database you want them moved.

Sub Initialize
    Dim s As New NotesSession
    Dim w As New NotesUIWorkspace
    Dim dbSource As NotesDatabase, dbDest As NotesDatabase
    Dim source As NotesView, dest As NotesView
    Dim vc As NotesViewEntryCollection
    Dim docDest As NotesDocument
    Dim ve As NotesViewEntry
    Dim folders() As String
    Dim i As Integer
    Dim ret, rez
    
    Set dbSource = s.CurrentDatabase
    
    Forall v In dbSource.Views
        If v.IsFolder Then
            i = i + 1
            Redim Preserve folders( i - 1 ) As String
            folders( i - 1 ) = v.Name
        End If
    End Forall
    
    ret = w.Prompt( PROMPT_OKCANCELLISTMULT, "Folder selection", 
"Select one or more folders to move.", folders(0), folders )
    If Isempty( ret ) Then 
        Messagebox "User canceled", , "Folder not selected" 
        Exit Sub
    Else
        Forall f In ret    
            Set source = dbSource.GetView( f )
            Set vc = source.AllEntries
            
            rez = w.Prompt( 13, "Database selection", 
"Choose the database to move the folder to" )
            If Isempty( rez ) Then Messagebox "User canceled", , 
"Database not selected" : Exit Sub
            
            Set dbDest = s.GetDatabase( rez(0), rez(1), False )
            Call dbDest.EnableFolder( f )
            
            Set ve = vc.GetFirstEntry
            Do Until ve Is Nothing
                Set docDest = ve.Document.CopyToDatabase( dbDest )
                Call docDest.PutInFolder( f )
                Set ve = vc.GetNextEntry( ve )
            Loop
            
            Call vc.RemoveAllFromFolder( f )
            Call source.Remove
        End Forall
    End If
End Sub


MEMBER FEEDBACK TO THIS TIP

Here's a quick add-on that will allow you to copy the design of the folder as well.

Sub Initialize
...<snip> ...
'Code added
Dim col As NotesViewColumn

... <snip> ...
Set dbDest = s.GetDatabase
( rez(0), rez(1), False )
Call dbDest.EnableFolder( f )

'Code added
Set dest = dbDest.GetView( f )

'Copy the columns from the 
source to the destination folder 
While dest.ColumnCount > 0
Call dest.RemoveColumn(dest.ColumnCount)
Wend
For i = 0 To source.ColumnCount-1
Set col = dest.CopyColumn(source.Columns(i), i+1) 
Next

'Code added
... <snip> ...

End Sub

—Raimund G.

Do you have comments on this tip? Let us know.

This tip was submitted to the SearchDomino.com tip library by member Marko Bonaci. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

This was first published in April 2006

Dig deeper on Lotus Notes Domino Agents

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchWinIT

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchVirtualDataCentre.co.uk

Close