Michael Deml
asked on
Export Lotus Noes View with specific folders to .csv
Hello,
i have found the following LotusScript Code wich exports LotusNotesView to .csv datasheet. The code works fine.
The problem is that when i start the Agent i need to be manualy on the folder that i want to export and it dosent work with the inbox.
How can i change the script that it export the folders that i need ? I need two of them: Inbox, and a Folder called "Workflow".
i have found the following LotusScript Code wich exports LotusNotesView to .csv datasheet. The code works fine.
The problem is that when i start the Agent i need to be manualy on the folder that i want to export and it dosent work with the inbox.
How can i change the script that it export the folders that i need ? I need two of them: Inbox, and a Folder called "Workflow".
Sub Initialize
Dim ws As New NotesUIWorkspace
Dim uiview As NotesUIView
Dim view As NotesView
' use the workspace to get the current view
Set uiview = ws.CurrentView
Set view = uiview.View
Dim filenames As Variant
'Dim cn As Variant
' Get filename from user using the current ViewName as the default file name
filenames = ws.SaveFileDialog( _
False,"File name",, "c:\", uiview.ViewName & ".csv")
If Not(IsEmpty(filenames)) Then
Call ViewCSVPrint (view, filenames(0) )
End If
End Sub
Sub ViewCSVPrint (view As NotesView, FileName As String )
Dim fileNum As Integer
Dim entry As NotesViewEntry
Dim vc As NotesViewEntryCollection
Dim rowstring As String
Dim cns As String
fileNum% = FreeFile()
Open filename For Output As fileNum%
' use the view column titles as the CSV headers
ForAll c In view.Columns
If cns = "" Then
cns = c.title
Else
cns = cns + +"," + c.title
End If
End ForAll
Print #fileNum%, cns
' now get and print the values for each row and column
Set vc = view.AllEntries
Set entry = vc.GetFirstEntry()
While Not entry Is Nothing
rowstring = ""
ForAll colval In entry.ColumnValues
If rowstring = "" Then
rowstring = colval
Else
rowstring = rowstring + +"," + colval
End If
End ForAll
Print #fileNum%, rowstring
Set entry = vc.GetNextEntry(entry)
Wend
Close fileNum%
End Sub
ASKER
thank you for the hints!
I changed the code like this:
Is this right ? Only Error i get is the filename that wont work anymore. Is there an alternative that set the databse name to default file name ?
I changed the code like this:
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = New NotesDatabase( "test", "plan.nsf" )
Dim view As NotesView
' getview folder
Set view = db.GetView( "test" )
Dim filenames As Variant
'Dim cn As Variant
' Get filename from user using the current ViewName as the default file name
filenames = ws.SaveFileDialog( _
False,"File name",, "c:\", uiview.ViewName & ".csv")
If Not(IsEmpty(filenames)) Then
Call ViewCSVPrint (view, filenames(0) )
End If
End Sub
Is this right ? Only Error i get is the filename that wont work anymore. Is there an alternative that set the databse name to default file name ?
Try view.ViewName...
ASKER
Nope dont work. It says: "Not a member: SaveFileDialog".
filenames = session.SaveFileDialog( _
False,"File name",, "c:\", View.ViewName & ".csv")
If Not(IsEmpty(filenames)) Then
Call ViewCSVPrint (view, filenames(0) )
End If
Ah, but that's because you have to declare and initialize ws. Add, at the start of your code :
Dim ws As New NotesUIWorkspace
Dim ws As New NotesUIWorkspace
Hi,
Does it work by now? It should, but if you still have some issues please tell me.
Regards, Sjef
Does it work by now? It should, but if you still have some issues please tell me.
Regards, Sjef
ASKER
first thanks again for your help!
But no it dont.
i added this: Dim uiview As NotesUIView
without it wouldnt work.
when i run the agent now it says error message: Object variable not set
i think i need to change this: Set uiview = ws.CurrentView
but i dont want the currentview ?
the actual code:
But no it dont.
i added this: Dim uiview As NotesUIView
without it wouldnt work.
when i run the agent now it says error message: Object variable not set
i think i need to change this: Set uiview = ws.CurrentView
but i dont want the currentview ?
the actual code:
Option Public
Option Explicit
Sub Initialize
Dim ws As New NotesUIWorkspace
Dim uiview As NotesUIView
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = New NotesDatabase( "test>", "test.nsf" )
Dim view As NotesView
' getview folder
Set view = db.GetView( "test" )
Dim filenames As Variant
'Dim cn As Variant
' Get filename from user using the current ViewName as the default file name
filenames = ws.SaveFileDialog( _
False,"File name",, "c:\", uiview.ViewName & ".csv")
If Not(IsEmpty(filenames)) Then
Call ViewCSVPrint (view, filenames(0) )
End If
End Sub
Option Public
Option Explicit
Sub Initialize
Dim ws As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
' getview folder
Set db = session.CurrentDatabase
Set view = db.GetView( "test" )
Dim filenames As Variant
'Dim cn As Variant
' Get filename from user using the current ViewName as the default file name
filenames = ws.SaveFileDialog( _
False,"File name",, "c:\", view.ViewName & ".csv")
If Not(IsEmpty(filenames)) Then
Call ViewCSVPrint (view, filenames(0) )
End If
End Sub
ASKER
this works: view.Name
View.ViewName was wrong.
View.ViewName was wrong.
Sub Initialize
Dim ws As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = New NotesDatabase( "test>", "test" )
Dim view As NotesView
' getview folder
Set view = db.GetView( "test" )
Dim filenames As Variant
'Dim cn As Variant
' Get filename from user using the current ViewName as the default file name
filenames = ws.SaveFileDialog( _
False,"File name",, "c:\", view.Name & ".csv")
If Not(IsEmpty(filenames)) Then
Call ViewCSVPrint (view, filenames(0) )
End If
End Sub
So now it gets my folder thats good. But i also want to output the inbox. If i do this it cant find the inbox ? and can i display the name of the folders in the csv file ?Set view = db.GetView( "inbox" )
Set view = db.GetView( "test" )
For the Inbox, try "($Inbox)". And how do you want to show folder names in the CSV file?
ASKER
( "$inbox" ) works thanks. But it only show either inbox or the folder test. If i do both it only gets me the folder not the inbox. If i do inbox he gets me the inbox.
Set view = db.GetView( "$inbox" )
Set view = db.GetView( "test" )
Just as the others, in a column. There are already column like name, subject, date etc.
Your function ViewCSVPrint accepts only one view, You cannot do "both", as your variable view contains ONE view.
Or do you want to export multiple views, in multiple csv files ?
Or do you want to export multiple views, in multiple csv files ?
ASKER
i want to export multiple views, in mutliple csv files. I have around 8 mai dbs that need to be exported. Is this posbile with one agent ? or should i do one agent for every mail db ?
In theory you can do everything using one agent, if that agent has access to all mail databases. If it's the practical thing to do I don't know. Other questions:
- how often doo you want to export all these folders/files?
- are folder names identical between mail databases, or else how do you know which folders to export?
- do you want to manually confirm each file name?
- how often doo you want to export all these folders/files?
- are folder names identical between mail databases, or else how do you know which folders to export?
- do you want to manually confirm each file name?
ASKER
- every day
- the folders are not the same. This is why i needed to define the folder name in the script.
- no, thats an important one that i definitely need to change. It would be better to set a specific name for every export.
- the folders are not the same. This is why i needed to define the folder name in the script.
- no, thats an important one that i definitely need to change. It would be better to set a specific name for every export.
If you want you can develop additional functionality for one or more mail databases, and put that inside the mail template. It would mean that you have to pay special attention during upgrades of your Domino environment, in order not to lose that functionality.
It might therefore be better to create a separate database, like this:
- you create a document per mail database that has to be exported
- in each document, you put the names of the folders you want to be exported
So the code of the agent would be:
For All mail databases
get export folder names
For All export folder names
Call export_folder(database, folder)
End For All
End For All
A document wouldn't need to contain more than a few fields:
- database name
- a checkbox showing all folders in that database
- an export file name ?
It might therefore be better to create a separate database, like this:
- you create a document per mail database that has to be exported
- in each document, you put the names of the folders you want to be exported
So the code of the agent would be:
For All mail databases
get export folder names
For All export folder names
Call export_folder(database, folder)
End For All
End For All
A document wouldn't need to contain more than a few fields:
- database name
- a checkbox showing all folders in that database
- an export file name ?
ASKER
Ok i will try that later! thank you!
one more important question: how can i change this to a fixed name ?
I dont want to always type the name.
one more important question: how can i change this to a fixed name ?
I dont want to always type the name.
' Get filename from user using the current ViewName as the default file name
filenames = ws.SaveFileDialog( _
False,"File name",, "c:\", view.Name & ".csv")
If Not(IsEmpty(filenames)) Then
Call ViewCSVPrint (view, filenames(0) )
That's why the new, separate database should be handy: for every mail database you store the name and its folders in a document.
Anyway, if you want a fixed name, just don't use ws.SaveFileDialog.
Anyway, if you want a fixed name, just don't use ws.SaveFileDialog.
Dim fname as String
fname= view.Name & ".csv"
Call ViewCSVPrint(view, fname)
Just asking: question answered? Please close it!
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Do not use the UIView or CurrentView, as they won't allow you to open any folder.
You have to get a NotesDatabase object first, eg from a NotesSession object.
Use it to get a NotesView object for a folder, using GetView.
Then call your function to export it to CSV.