Update Export File
SV_Will
Member Posts: 12
Hi there,
within a CodeUnit I generate a File "Production.csv". I would like to add a new line everytime into the file I run the CodeUnit!
But without the
IF EXISTS(FileNameProdZahlen) THEN
ERASE(FileNameProdZahlen);
I get the Error "The File does already exist!"
Possible?
Thanks a Lot !!
within a CodeUnit I generate a File "Production.csv". I would like to add a new line everytime into the file I run the CodeUnit!
But without the
IF EXISTS(FileNameProdZahlen) THEN
ERASE(FileNameProdZahlen);
I get the Error "The File does already exist!"
Possible?
Thanks a Lot !!
0
Comments
-
not sure but it might be somehting like this (snipit from how i can keep exporting info to the same file and the file just keep builing upon itself.
Hopefully this can give you an idea. I believe if you search too there was a similar post a while back that you possibly could find. Perhaps search for Add to existing text file :-kOpenMyFile() Status : Boolean FormatMyFileName; MyFile.TEXTMODE(TRUE); MyFile.WRITEMODE(TRUE); IF MyFile.OPEN(MyFileName) THEN BEGIN BeginFileLength := MyFile.LEN; MyFile.SEEK(BeginFileLength); MyFile.TRUNC; // write your field w/code here EXIT(TRUE); END; MyFile.CLOSE;
here are some more posts
http://www.mibuso.com/forum/viewtopic.php?t=4706
http://www.mibuso.com/forum/viewtopic.php?t=13457
http://www.mibuso.com/forum/viewtopic.php?t=8364
probably more if you search0 -
I believe you are looking more for something like this...
OnRun() MyFile.TEXTMODE(TRUE); MyFile.WRITEMODE(TRUE); IF EXISTS(FileNameProdZahlen) THEN MyFile.OPEN(FileNameProdZahlen) ELSE MyFile.CREATE(FileNameProdZahlen); IF MyFile.LEN > 0 THEN MyFile.SEEK(MyFile.Len); MyFile.CREATEOUTSTREAM(oStream); oStream.WRITETEXT('CodeUnit Access: ' + FORMAT(CURRENTDATETIME) + ' / ' + USERID); oStream.WRITETEXT(); MyFile.CLOSE;0 -
I am having some trouble with this.
I have created a Report with nested dataitems. a line of code in our business logic will call this report if a certain condition is met. The report will create a CSV file if none exists, and append to the CSV file when it does exist.
Creation of the file is clockwork. no problems. I am, however, having issues with the append. I have tried both Savatage and Xypher's suggestions, but each time i am getting appending at the start of the file, and that is no good.
I have three data items.
Integer (OnAfterGetRecord I write field label data, but only when the file is being created)
Sales Header (OnAfterGetRecord, I fill some variables with Sales Header values)
Sales Line (linked to the header, on AfterGetRecord, I fill some var. w/ data from tables linked to sales line and do my outstream.write).
On PreReport, I have the following code://Mibuso sample code for appending to an existing file. POFile.TEXTMODE(TRUE); POFile.WRITEMODE(TRUE); IF FileForExport THEN POFile.OPEN(sFileName) ELSE POFile.CREATE(sFileName); IF POFile.LEN > 0 THEN POFile.SEEK(POFile.LEN); POFile.CREATEOUTSTREAM(POOutstream); FileForExport() FileFound : Boolean //temporary hard-coded directory to store CSV files for upload to Customer sFilePath := '\\fps\test\'; CLEAR(recPOFile); recPOFile.SETFILTER(Path,'%1',sFilePath); recPOFile.SETFILTER(Name,'%1','@*.csv'); recPOFile.SETRANGE("Is a file",TRUE); IF NOT recPOFile.FIND('-') THEN BEGIN sNoSeries := 'WM_POTRACK'; NoSeriesMgt.InitSeries(sNoSeries,sNoSeries,0D,sBatchNo,sNoSeries); sFile := OutVendorNo + '_' + sBatchNo + '.csv'; sFileName := sFilePath + sFile; bCreateCSV := TRUE; EXIT(FALSE) END ELSE BEGIN sFileName := sFilePath + recPOFile.Name; EXIT(TRUE); END;
it is still early draft of code, so forgive the hard-coding.
my issue is that when i open the existing file and seek the LEN, I begin writing at the start of the file, not the end. I assume I am missing a line of code somewhere, but my search of the forum only talks about using LEN and going from there. Any thoughts on what i am doing wrong?
thanks!kind of fell into this...0 -
Hi,
A file.SEEK to LEN should be fine. here's a test with your code..POFile.TEXTMODE(TRUE); POFile.WRITEMODE(TRUE); POFile.OPEN('C:\users\public\dave.txt'); IF POFile.LEN > 0 THEN POFile.SEEK(POFile.LEN); POFile.WRITE( ' Inserting time ' ); POFile.WRITE( ' Time - ' + FORMAT( TIME ) ); POFile.CLOSE;
You have not shown the writing code - is it possible that another seek is affecting it?0 -
thank you!DaveT wrote:Hi,
A file.SEEK to LEN should be fine. here's a test with your code..POFile.TEXTMODE(TRUE); POFile.WRITEMODE(TRUE); POFile.OPEN('C:\users\public\dave.txt'); IF POFile.LEN > 0 THEN POFile.SEEK(POFile.LEN); POFile.WRITE( ' Inserting time ' ); POFile.WRITE( ' Time - ' + FORMAT( TIME ) ); POFile.CLOSE;
You have not shown the writing code - is it possible that another seek is affecting it?
here is my code for writing. it occurs in the sales line dataitem. i was using Outstream, and maybe that is my problem? your example shows POFile.WRITE....but i do a POFile.CREATEOUTSTREAM.POOutstream.WRITETEXT(OutVendorNo + ',' + OutPONo + ',' + OutStoreNo + ',' + OutSONo + ',' + FORMAT(OutEstShipDate) + ',' + FORMAT(OutActShipDate) + ',' + FORMAT(OutEstDelDate) + ',' + OutShipName + ',' + OutShipAddress + ',' + OutShipCity + ',' + OutShipState + ',' + OutSCAC + ',' + OutProNo + ',' + OutBOLNo + ',' + OutPalletIDNo + ',' + OutContainerType + ',' + OutContainerNo + ',' + FORMAT(OutQtyContainer) + ',' + OutWMItemNo + ',' + OutItemNo + ',' + OutItemDesc + ',' + OutWMCompItemNo + ',' + OutCompItemNo + ',' + OutCompItemDesc + ',' + FORMAT(OutQtyOrdered) + ',' + FORMAT(OutQtyShipped) + ',' + OutStatus + ',' + OutShipCondition + ',' + OutPartsType ); //Without following WRITETEXT, the text file that is created will be one continuous string. This breaks the line. POOutstream.WRITETEXT();
there is no other SEEK.kind of fell into this...0 -
Hi,
I generally use the WRITE command with text and use the OUTSTREAM with binary etc. I haven't tried a SEEK/OUTSTEAM combination before but it should work.
Two suggestions:
1. Use the WRITE command
2. Put the SEEK after creating the OUTSTREAM.0 -
DaveT wrote:Hi,
I generally use the WRITE command with text and use the OUTSTREAM with binary etc. I haven't tried a SEEK/OUTSTEAM combination before but it should work.
Two suggestions:
1. Use the WRITE command
2. Put the SEEK after creating the OUTSTREAM.
hello, thanks again.
I tried putting the seek after creating the OUTSTREAM, but with the same results. I will try your other idea next!kind of fell into this...0 -
using the WRITE command instead of WRITETEXT did it! I got rid of the outstream and now my file appends as desired!
\:D/
thanks so much, DaveT!kind of fell into this...0 -
-
It's great when a plan comes together, isn't it! =D>0
-
it sure is. this site is great for getting another set of eyes on a problem, and helped me through it, as usual.
it did appear that the SEEK was working - i created some variables to show me what position it was on after doing the seek and the number looked correct. when it came to writing the output, however, it seemed to ignore the position altogether.kind of fell into this...0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 322 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
