I want to create a new text file when I press some specific button and write some sales line details in that text file.Can anybody please let me know how to create a new text file by coding.
You can either do it through dataports or through working with the files itself.
I would suggest using a dataport by setting the filename and the filters (SETTABLEVIEW). It's much easier to maintain.
Otherwise you can use the following code:
Global Variables
Name Type Size
OutFile File
OutFileName Text 1000
txtLine Text 1000
SalesLine Record Sales Line
Code
OutFileName := 'C:\SalesOrder' + SalesLine."Document No." + '.txt';
OutFile.WRITEMODE(TRUE);
OutFile.TEXTMODE(TRUE);
SalesLine.SETRANGE(<set your filters>)
if SalesLine.find('-') then repeat
txtLine := <field1> + ',' + <field2> + etc.
OutFile.WRITE(txtLine);
Until SalesLine.NEXT = 0;
OutFile.close;
You will probably need to add more code to so that you can avoid creating 'empty' files.
Comments
You can either do it through dataports or through working with the files itself.
I would suggest using a dataport by setting the filename and the filters (SETTABLEVIEW). It's much easier to maintain.
Otherwise you can use the following code:
Global Variables
Code
You will probably need to add more code to so that you can avoid creating 'empty' files.
Regards,
Gustav
My humblest apologies :oops: :oops:
For an example of how to create a file and to write data on that file using X++, please refer to -
http://www.harishm.com/Navision/Code.html
Regards,
Harish Mohanbabu
Long way to go before I sleep..