Add INDEX Field to File Name For Custom CSV Export Script

  • 560 Views
  • Last Post 4 weeks ago
Jakarta Development posted this 25 March 2014

Greeting,

Can anyone help me (again) on how to add index field to file name for my custom csv export?
Recently I've had help from a member to enclosed double quotes on csv export here.

As you can see, in order to enclose double quotes, I need to define also the file name output:
Dim namafiledetail as string = "D:\YOURTARGETFOLDER\export.csv"

This restricts me to one file naming as defined.

Is there any way that I can implement
Index:\Document Section 1\NAME

as an output for my custom csv file name?

Thank you in advance.


Order By: Standard | Newest | Votes
ScanAddicted posted this 25 March 2014



dim namafiledetail as string = "d:\YOURTARGETFOLDER\" & document.field("Document Section1\NAME").value & ".csv

Jakarta Development posted this 25 March 2014

@ScanAddicted I need to buy you some beers!

The619 posted this 15 April 2019

  Hey, @Jakarta Development - Is there any way you can give me some example of custom csv export scripts? 

uhuglue posted this 4 weeks ago

Hopefully this helps you. Basic script done for a short customer demo to combine standard capture fields with table line items as ABBYY seems to export it into different files by default.

' Declare variables.
Dim fso, txtFile, fileName, table, row, cell, fixAdress, cellCtr
' Create file system object.
Set fso = CreateObject("Scripting.FileSystemObject")
' Set the filename.
'fileName = "\\mypc\abbyy_export\export_" & me.Field("Document Section 1\blkAccount").Value & ".csv"
fileName = "\\mypc\abbyy_export\export.csv"
Set table = me.Field("Document Section 1\blkTable1")

' If the export file doesn't exist, then create it.
If Not fso.FileExists(fileName) Then    
    Set txtFile = fso.CreateTextFile(fileName, true)
    For Each row In table.items
        ' Fix the address field which may have comma's and all kinds of weird shit.
        fixAddress = me.Field("Document Section 1\blkAddress").Value
        fixAddress = replace(fixAddress, vbLf, "")
        fixAddress = replace(fixAddress, ",", " ")
        fixAddress = replace(fixAddress, vbTab, "")
        ' Write the single document row values first, followed by the table cell values.
        txtFile.Write me.Field("Document Section 1\blkAccount").Value & "," & me.Field("Document Section 1\blkTakenBy").Value & "," &_
            me.Field("Document Section 1\blkDate").Value & "," & me.Field("Document Section 1\blkTime").value & "," &_
            me.Field("Document Section 1\blkWaybillDateTime").Value & "," & me.Field("Document Section 1\WaybillTime").value & "," &_
            me.Field("Document Section 1\blkWaybill").Value & "," & fixAddress & "," &_
            me.Field("Document Section 1\blkAttention").value & "," & me.Field("Document Section 1\blkNumber").value & ","   
        ' Write the individual cell values.
        cellCtr = 0
        For each cell In row.Children
            If cellCtr = 1 then
                txtFile.Write cell.value
            Else
                txtFile.Write cell.value & ","
            End if
            cellCtr = cellCtr + 1
        Next
        txtFile.WriteBlankLines 1
    Next
' If the export file does exist, then append to it.
Else
    Set txtFile = fso.OpenTextFile(fileName, 8, True)
    For Each row In table.items
        ' Fix the address field which may have comma's and all kinds of weird shit.
        fixAddress = me.Field("Document Section 1\blkAddress").Value
        fixAddress = replace(fixAddress, vbLf, "")
        fixAddress = replace(fixAddress, ",", " ")
        fixAddress = replace(fixAddress, vbTab, "")
        ' Write the single document row values first, followed by the table cell values.
        txtFile.Write me.Field("Document Section 1\blkAccount").Value & "," & me.Field("Document Section 1\blkTakenBy").Value & "," &_
            me.Field("Document Section 1\blkDate").Value & "," & me.Field("Document Section 1\blkTime").value & "," &_
            me.Field("Document Section 1\blkWaybillDateTime").Value & "," & me.Field("Document Section 1\WaybillTime").value & "," &_
            me.Field("Document Section 1\blkWaybill").Value & "," & fixAddress & "," &_
            me.Field("Document Section 1\blkAttention").value & "," & me.Field("Document Section 1\blkNumber").value & ","    
        ' Write the individual cell values.
        cellCtr = 0
        For each cell In row.Children
            If cellCtr = 1 then
                txtFile.Write cell.value
            Else
                txtFile.Write cell.value & ","
            End if
            cellCtr = cellCtr + 1
        Next
        txtFile.WriteBlankLines 1
    Next
End If

' Coup de grace.
txtFile.close
Set txtFile = Nothing
Set fso = Nothing

Close