Auch wenn der obige Beitrag schon Jahre alt ist, hat er mir sehr geholfen.
Wenn ich beispielsweise alle möglichen Feldtypen zu exportieren hatte, dann habe ich jedes benötigte Dokumentfeld und Attribute zur Verarbeitiung in ein string array gespeichert (sFldArr).
%REM ---
sFldArr(n,1) -> field name
sFldArr(n,2) -> flag for data type
sFldArr(n,3) -> flag for multi-value field (0 = single value, 1 = multi-value)
sFldArr(n,4) -> flag for check required on field containing CRLF / text qualifier, separator if no text qualifier is chosen
sFldArr(n,5) -> field content
%END REM
Ein EXPORTCSV subroutine (library) Aufruf
Sub NotesViewExportCSV (server As String, dbpath As String, sView As String,_
ExpFilePath As String, sSep As String, tq As String, replStr As String, mvfSep As String,_
sFldName As Variant, sChkFldVal As Variant)
%REM subroutine for export of view documents where field names are provided in an array
* single-/multi-value flag added, if multi-value then array is imploded to a string with mvfSep as separator.
* replace string for unwanted characters
* if field value contains text qualifier mask it (according to RFC 4180)
Description:
subroutine goes through view and exports defined list of fields document by document, applies given filter
for skipping records and transforms field values as requested
server server name
dbpath database path
sView view name (alias name preferred)
ExpFilePath full file path for export file
sSep separator for CSV file
tq quote character
replStr replace string
mvfSep multi-value field separator for implode
sFldName array of field names (1), data types (2), single-/multi-value flags (3), check flags (4), values (5)
sChkFldVal array with field names, valid values separated by tilde and actual value to check
exportiert die Daten in ein CSV File.
Hierbei wird das Dokumentfeld in ein Feld vom Typ Variant gelesen. Das hat den Vorteil, dass man Mehrfachwertfelder ebenfalls damit behandeln kann.
...
For i = LBound(sFldName,1) To UBound(sFldName,1)
If doc.Hasitem(sFldName(i,1)) Then
vfldvalue = doc.GetItemValue(sFldName(i,1))
Select Case sFldName(i,2)
Case "T":
If sFldName(i,3) = "0" Then
sfldvalue = vfldvalue(0)
Else
sfldvalue = Implode(vfldvalue, mvfSep)
End If
Case "I":
sfldvalue = CStr(vfldvalue(0))
If sFldName(i,3) = "1" Then
For j = LBound(vfldvalue)+1 To UBound(vfldvalue)
sfldvalue = sfldvalue & mvfSep & CStr(vfldvalue(j))
Next
End If
...
Inzwischen habe ich den Anspruch erweitert und wollte noch ein Attribut im Array sFldArr aufnehmen: Formatierung bzw Konvertierung. Für Felder vom Typ DateTime gibt man zum Beispiel den Formatierungsstring an (z.B. "YYYY-MM-DD hh:nn:ss") und mit den Formatbefehl angewendet, wird der Wert entsprechend in den String zur Ausgabe gespeichert.
Wenn man aber nun Namensfelder mit Mehrfachwerten hat (z.B. $UpdatedBy) und diese als konkatenierten String OHNE die OU und O Hierarchie ausgeben will, so muss man auf das NotesName item die Funktion 'Common' anwenden. Und das geht nicht wenn man den das Variant Array verwenden will und es geht auch nicht auf einzelne Variant Arraywerte.
Man muss ein NotesItem Objekt zuweisen und über dieses arbeiten.
Weiter unten habe ich meinen vollständigen Code hinzugefügt und habe den nicht funktionierenden Code auskommentiert und gekennzeichnet wo der immer gleiche / selbe Fehler auftritt.
Option Public
Option Declare
%Include "lsconst.lss"
Sub Initialize
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim session As New NotesSession
Dim db As NotesDatabase
Dim collection As NotesDocumentCollection
Dim doc As NotesDocument
Dim i As Integer, j As Integer
Dim s_val As String
Dim v_val As Variant
Dim Nam As NotesName
Set db = session.CurrentDatabase
Set collection = db.UnprocessedDocuments
%REM if you like to process all selected documents
For i = 1 To collection.Count
Set doc = collection.GetNthDocument(i)
...
Next
%ENDREM
%REM if you like to process only the first of selected documents
Set doc = collection.GetFirstDocument
If Not doc Is Nothing Then
' execution statements
End If
%ENDREM
Set doc = collection.GetFirstDocument
If Not doc Is Nothing Then
' without .Common you can work with variants - no error will occur
v_val = doc.GetItemValue("NameField01")
s_val = v_val(0)
For i = LBound(v_val)+1 To UBound(v_val)
s_val = s_val + ";" + v_val(i)
Next i
MessageBox s_val, MB_OK + MB_ICONINFORMATION + MB_DEFBUTTON1 + MB_APPLMODAL, "s_val (String) from v_val(i)"
' with .Common you first have to get the NotesName Items to a NotesName and from there apply .Common and add it to string - version 1
Set Nam = session.CreateName(doc.NameField01(0))
s_val = Nam.Common
For i = LBound(doc.NameField01)+1 To UBound(doc.NameField01)
Set Nam = session.CreateName(doc.NameField01(i))
s_val = s_val + ";" + Nam.Common
Next
MessageBox s_val, MB_OK + MB_ICONINFORMATION + MB_DEFBUTTON1 + MB_APPLMODAL, "s_val (String) from For LBound .. UBound Nam.Common - version1"
' with .Common you first have to get the NotesName Items to a NotesName and from there apply .Common and add it to string - version 2
s_val = ""
ForAll value In doc.GetItemValue("NameField01")
Set Nam = session.CreateName(value)
If s_val = "" Then
s_val = Nam.Common
Else
s_val = s_val + ";" + Nam.Common
End If
End ForAll
MessageBox s_val, MB_OK + MB_ICONINFORMATION + MB_DEFBUTTON1 + MB_APPLMODAL, "s_val (String) from For LBound .. UBound Nam.Common - version2"
%REM below code is not working the row is marked where ERROR pops up
s_val = doc.GetItemValue("NameField01")(0)
For i = LBound(doc.NameField01)+1 To UBound(doc.NameField01)
s_val = s_val + ";" + doc.GetItemValue("NameField01")(i).Common 'ERROR: object variable not set
Next i
MessageBox s_val, MB_OK + MB_ICONINFORMATION + MB_DEFBUTTON1 + MB_APPLMODAL, "s_val (String) doc.GetItemValue(""NameField01"")(i).Common"
s_val = doc.GetItemValue("NameField01")(0)
For i = LBound(doc.NameField01)+1 To UBound(doc.NameField01)
s_val = s_val + ";" + doc.NameField01(i).Common 'ERROR: object variable not set
Next i
MessageBox s_val, MB_OK + MB_ICONINFORMATION + MB_DEFBUTTON1 + MB_APPLMODAL, "s_val (String) from doc.NameField01(i).Common"
v_val = doc.GetItemValue("NameField01")
s_val = v_val(0).Common 'ERROR: object variable not set
For i = LBound(v_val)+1 To UBound(v_val)
s_val = s_val + ";" + v_val(i).Common
Next i
MessageBox s_val, MB_OK + MB_ICONINFORMATION + MB_DEFBUTTON1 + MB_APPLMODAL, "s_val (String) From v_val(i).Common"
s_val = Implode(doc.GetItemValue("NameField01").Common,";") 'ERROR: object variable not set
MessageBox s_val, MB_OK + MB_ICONINFORMATION + MB_DEFBUTTON1 + MB_APPLMODAL, "s_val (String) from Implode doc.GetItemValue(""NameField01"").Common"
%ENDREM
Else
MessageBox "You did not select any document in view", MB_OK + MB_ICONINFORMATION + MB_DEFBUTTON1 + MB_APPLMODAL, "Document Selection"
End If
End Sub