/
CustomerLedgerEntriesExt.al
46 lines (45 loc) · 2.05 KB
/
CustomerLedgerEntriesExt.al
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
pageextension 50102 CustomerLedgerEntriesExt extends "Customer Ledger Entries"
{
actions
{
addfirst(processing)
{
action(ExportToExt)
{
Caption = 'Export Items via TextBuilder';
ApplicationArea = All;
PromotedCategory = Process;
Promoted = true;
Image = Export;
trigger OnAction()
var
TempBlob: Codeunit "Temp Blob";
InS: InStream;
OutS: OutStream;
FileName: Text;
TxtBuilder: TextBuilder;
CustLedgerEntry: Record "Cust. Ledger Entry";
begin
FileName := 'TestCSVFile_' + UserId + '_' + Format(CurrentDateTime) + '.csv';
TxtBuilder.AppendLine('Posting Date' + ',' + 'Document Type' + ',' + 'Document No.' + ',' + 'Customer No.' + ',' + 'Amount(LCY)');
CustLedgerEntry.Reset();
CustLedgerEntry.SetAutoCalcFields("Amount (LCY)");
if CustLedgerEntry.FindSet() then
repeat
TxtBuilder.AppendLine(AddDoubleQuotes(Format(CustLedgerEntry."Posting Date")) + ',' + AddDoubleQuotes(Format(CustLedgerEntry."Document Type")) + ',' +
AddDoubleQuotes(CustLedgerEntry."Document No.") + ',' + AddDoubleQuotes(CustLedgerEntry."Customer No.") + ',' +
AddDoubleQuotes(Format(CustLedgerEntry."Amount (LCY)")));
until CustLedgerEntry.Next() = 0;
TempBlob.CreateOutStream(OutS);
OutS.WriteText(TxtBuilder.ToText());
TempBlob.CreateInStream(InS);
DownloadFromStream(InS, '', '', '', FileName);
end;
}
}
}
local procedure AddDoubleQuotes(FieldValue: Text): Text
begin
exit('"' + FieldValue + '"');
end;
}