Hi All,
How can I save the text file instead of prefix the file name (refer to picture below) in report? Such as let user to save their own .txt file in the particular folder location or prompt a window to request for "Open" , "Save" or "Cancel"?
Best Regards,
Vanessa
*This post is locked for comments
hi,
how to solve this error ?
Above video really helped me.
Hi Vanessa,
how you solved this issue ?
Thank you
Gero
Hi Vanessa,
1. To export the details with separator, you can use FORMAT function to convert decimal to text before writing to file, for example, gFil_File.WRITE(FORMAT(Amount)); There are parameters to help you get desired format msdn.microsoft.com/.../dd301367(v=nav.70).aspx
2. To export all details of TotalAmount from VAT Statement:
2.1. Prepare server file OnPreReport instead of OnPostReport, move below code to the end of OnPreReport:
//Server side: process data with temporary file
gTxt_ServerFileName := gCoU_FileMgmt.ServerTempFileName('txt');
gFil_File.CREATE(gTxt_ServerFileName);
gFil_File.TEXTMODE(TRUE);
2.2. Add VAT Entry data item and handle the OnAfterGetRecord trigger.
Hi,
Thousand thanks for your help.
BTW, may I know how to export all details of TotalAmount from VAT Statement and export the details with separator? I have no idea on this...
E.g.:
Hi Vanessa,
I send you sample report object in text format:
- Report Request Page with Client File Name and Open After Download option.
- OnPreReport: check Client File Name not blank.
- OnPostReport: process at server side, download to client, then open client file or not.
--------------------------------------------------
OBJECT Report 50001 Test Save File
{
OBJECT-PROPERTIES
{
Date=10/25/14;
Time=[ 6:57:57 AM];
Modified=Yes;
Version List=;
}
PROPERTIES
{
OnPreReport=BEGIN
//Check input client file name
IF (gTxt_ClientFileName = '') THEN
ERROR('Please specify Client File Name!');
END;
OnPostReport=BEGIN
//Server side: process data with temporary file
gTxt_ServerFileName := gCoU_FileMgmt.ServerTempFileName('txt');
gFil_File.CREATE(gTxt_ServerFileName);
gFil_File.TEXTMODE(TRUE);
gFil_File.WRITE('Test 1');
gFil_File.WRITE('Test 2');
gFil_File.CLOSE;
//Download file from Server to Client
gCoU_FileMgmt.DownloadToFile(gTxt_ServerFileName, gTxt_ClientFileName);
//Open file after download
IF gBol_OpenAfterDownload THEN
HYPERLINK(gTxt_ClientFileName);
END;
}
DATASET
{
}
REQUESTPAGE
{
PROPERTIES
{
SaveValues=Yes;
}
CONTROLS
{
{ 1 ; ;Container ;
Name=ContentArea;
ContainerType=ContentArea }
{ 2 ;1 ;Group ;
Name=Client File;
GroupType=Group }
{ 3 ;2 ;Field ;
Name=File Name;
SourceExpr=gTxt_ClientFileName;
OnAssistEdit=BEGIN
gTxt_ClientFileName := gCoU_FileMgmt.SaveFileDialog('Save As', 'Output File.txt', 'Text File (*.txt)|*.txt');
END;
}
{ 4 ;2 ;Field ;
Name=Open After Download;
SourceExpr=gBol_OpenAfterDownload }
}
}
LABELS
{
}
CODE
{
VAR
gTxt_ClientFileName@1000 : Text;
gTxt_ServerFileName@1001 : Text;
gCoU_FileMgmt@1002 : Codeunit 419;
gFil_File@1003 : File;
gBol_OpenAfterDownload@1004 : Boolean;
BEGIN
END.
}
}
hi,
try simple version:
in report - OnPostReport()
------------------------------------------------------
FileName := FileManagement.SaveFileDialog('Save as','file.txt','Text files (*.txt)|*.txt');
IF FileName = '' THEN
ERROR('No filename given.');
SrvFileName := 'c:\temp\srv-file.txt';
File.CREATE(SrvFileName);
File.CREATEOUTSTREAM(outStream);
outStream.WRITETEXT('line 1');
outStream.WRITETEXT;
outStream.WRITETEXT('line 2');
outStream.WRITETEXT;
File.CLOSE;
FileManagement.DownloadToFile(SrvFileName,FileName);
Hi,
May I know which section I should put? I had write the code as you mentioned but still cannot. Am I locate in wrong section?
1) Client side
2) Server side
3) Download from server to client
Please advise.
Hi Vanessa,
Take a look at my Query and Excel Report Tool code on NAV 2013:
//1. Client side: user specifies file name or cancel
lTxt_ClientFileName := gCoU_FileMgmt.SaveFileDialog('[4Bz] Download Excel Template File', 'Navision Query and Excel Template', 'Excel File (*.xlsx)|*.xlsx');
IF (lTxt_ClientFileName = '') THEN
EXIT;
//2. Server side: process data with temporary file
lTxt_ServerFileName := gCoU_FileMgmt.ServerTempFileName('xlsx');
////Your code here////
//3. Download file from Server to Client
gCoU_FileMgmt.DownloadToFile(lTxt_ServerFileName, lTxt_ClientFileName);
Hi,
Yes, I had choose the file location. Actually I wish to export the Total Amount of VAT Statement report into text file. Code like:-
File1.CREATE(FileName);
File1.CREATEOUTSTREAM(OutStreamObj);
OutStreamObj.WRITETEXT (FORMAT(TotalAmount, 0, '<Precision,2:2><Standard Format,1>'));
OutStreamObj.WRITETEXT ('|');
File1.CLOSE;
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156