Exporting Data to File
Philipp Knecht
Hi,How can i export the info to a txt file when printing a document.
Problem:
I've made a Script that exports the documentheader info but I'm not able to export the documentrows (items, quantity...). Does anybody have a sample how to do that? See my script below.
Dim inhoud As String
Dim blancoregels As String
Dim Bestandsnaam As String
Dim i As Integer
dim header as string
Dim header1 As String
Dim rows As String
Dim footer As String
Dim adres As String
Dim straat As String
Dim iCRStraat As Integer
Dim iLenAdres As Integer
Dim gemeentesub As String
Dim gemeente As String
Dim iCRLand As Integer
Dim land As String
Dim iLenGemeente As Integer
Bestandsnaam = "Factuur" & "_" & GetData("B1_Data.Document.DocNum") & "_" & Format(Now,"ddmmyyyy_hhmm")
For i=4 To 87
blancoregels = blancoregels & vbcrlf & i
Next
adres = GetData("B1_Data.Document.Address")
iLenAdres = Len(adres)
iCRStraat = adres.IndexOf(Chr(13))
straat = adres.Substring(0,iCRStraat)
gemeentesub = adres.Substring(iCRStraat + 1,iLenAdres - iCRStraat - 1)
iLenGemeente = len(gemeentesub)
iCRLand = gemeentesub.IndexOf(Chr(13))
land = gemeentesub.Substring(iCRLand + 1, iLenGemeente - iCRLand -1)
gemeente = gemeentesub.Substring(0, iCRLand)
header = "~BEGINOFDOC" & vbcrlf & Replace("~PIFUSE 'FAKRET'", "'", "''") & vbcrlf & "~END"
header1 = "88" & vbtab & GetData("B1_Data.Document.DocDate") & vbtab & LD.FStr(PageNumber,"##0") & vbcrlf & _
"89" & vbtab & "*" & vbtab & GetData("B1_Data.BusinessPartner.CardName") & vbcrlf & _
"90" & vbtab & vbtab & vbtab & straat & vbtab & "B" & vbtab & GetData("B1_Data.Document.DocNum") & vbcrlf & _
"91" & vbtab & vbtab & vbtab & gemeente & vbcrlf & _
"92" & vbtab & vbtab & vbtab & land & vbcrlf & _
"93" & vbtab & vbtab & vbcrlf & _
"94" & vbtab & "R 126-201" & vbcrlf & _
"95" & vbtab & vbcrlf & _
"96" & vbtab & "Order:" & GetData("B1_Data.Document.numatcard") & vbcrlf & _
"97" & vbtab & "*" & vbtab & GetData("B1_Data.BusinessPartner.CardName") & vbtab & "FC" & vbcrlf & _
"98" & vbtab & vbtab & LD.MultiLine(Document("Address2"))& VBCrlf & _
"AAN U GELEVERD DOOR TUSSENKOMST VAN INTERLOGICA B.V." & vbcrlf & vbcrlf
rows = GetData("B1_Data.Row.ItemCode)
inhoud = header & blancoregels & vbcrlf & header1 & rows & footer
My.Computer.FileSystem.WriteAllText(("C:Documents and SettingsEric van HorssenMijn documentenB1CoresuiteExportfiles" & Bestandsnaam & ".txt"), _
inhoud,False)
Philipp Knecht
Here is a small example which shows the concept:In the CommonScript:
[quote]Dim fileContent As String
In the GetDataScript of the Document DataBand:
[quote]' Initalise with Header Data
fileContent = Document("DocNum")
In the GetDataScript of the DocumentRow DataBand:
[quote]fileContent &= vbcrlf & DocumentRow("ItemCode")
If DocumentRow.IsLastLine() AND NOT Engine.IsDoublePass Then
System.IO.File.WriteAllText("c:export.txt",fileContent)
End If
hth
0
Please sign in to leave a comment.
Comments
0 comments