Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Suggested answer

Creating Extension to import General Journal CSV file

Posted on by 87
I would like to know about importing data from a .csv file to a journal (General Journal page 39).
I am able to read the .CSV file but not able to figure out
1. how start inserting the line
2. What all fields to be inserted and are mandatory such that it does not create any error on Posting
3. Is the following data sufficient to upload to General Journal?
 
CSV looks like the following table
!HeaderHeaderIDTypeDateAccountNAMEAmount
!LineLineIDTypeDateAccountNAME of Shortcut Dimension 2Amount
!EndHeader     
Header EFT10/19/20231120 EFT-1096.84
Line EFT10/19/202321402140-20.09
Line EFT10/19/20232140Dim1300
Line EFT10/19/20232140Dim1600
Line EFT10/19/202340224022-2300
Line EFT10/19/20232140Dim1200
EndHeader     
 
The Code that i have written so far is as follows:-
 
pageextension 50100 ImportJournal extends /General Journal/
{
    actions
    {
        // Adding a new action group 'ImportData'
        addlast(processing)
        {
            group(ImportData)//NewActionGroup
            {
                Caption = 'Import Data';
                action(ImportJournal)
                {
                    ApplicationArea = All;
                    Caption = 'Import Journals';
                    Image = ImportExcel;
                    ToolTip = 'Import EFT *.csv Format Only';
                    trigger OnAction();
                    var
                        InS: InStream;
                        FileName: Text[100];
                        UploadMsg: Label 'Please upload EFT Journal CSV file';
                        Ext: Text[5];
                        FileManagement: Codeunit /File Management/;
                    begin

                        CSVBufferS.Reset();
                        CSVBufferS.DeleteAll();
                        if UploadIntoStream(UploadMsg, '', '', FileName, InS)
                        then begin
                            Ext := CopyStr(FileName, StrLen(FileName) - 3, StrLen(FileName));
                            if Ext.ToLower() = '.csv' then begin
                                CSVBufferS.LoadDataFromStream(InS, ',');
                                CSVBufferS.GetNumberOfLines();
                                ImportCSVGeneralJournalData();
                            end
                            ELSE
                                Error(UploadMsg);
                        end
                    end;
                }
            }
        }
    }
    var
        myInt: Integer;
        CSVBufferS: Record /CSV Buffer/;
    
local procedure GetValueAtCell(RowNo: Integer; ColNo: Integer): Text
    begin
        CSVBufferS.Reset();
        if CSVBufferS.Get(RowNo, ColNo) then
            exit(CSVBufferS.Value)
        else
            exit('');
    end;
 
    [TryFunction]
    local procedure ImportCSVGeneralJournalData()
    var
        GenJourLinRec: Record /Gen. Journal Line/;
        RowNo: Integer;//To iterate throught the rows of CSV
        MaxRow: Integer;//Stores the last row number
        DataType: Text[50];//To check the the value in column 1
        LineCount: Integer;//To get the number of lines processed
        //to check TYPE='EFT' or not
        TransactionType: Code[20];
    begin
        GenJourLinRec.RESET;
        RowNo := 0;
        MaxRow := 0;
        LineCount := 0;
        CSVBufferS.Reset();
        if CSVBufferS.FindLast() then begin
            MaxRow := CSVBufferS./Line No./;
        end;
        for RowNo := 4 to MaxRow do begin
            DataType := GetValueAtCell(RowNo, 1);
            if (DataType in ['Header', 'Line']) then begin
                TransactionType := GetValueAtCell(RowNo, 3);
                If ((TransactionType <> 'EFT')) then
                    Error('TRNSTYPE = EFT is not found')
                if DataType = 'Header' then begin
                    //
                    //
                    //
                end else
                    if DataType = 'Line' then begin
                        //
                        //
                        //
                        //
                    end;
            end;
        end;
        Message('Total Line %1 Processed Successfully from .CSV file.', LineCount);
    end;
}
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 68,664 Super User 2024 Season 2 on at
    Creating Extension to import General Journal CSV file
    Hi, hope the following helps.
    Dynamics 365 Business Central: How to import data from CSV (comma-separated values) file
     
     
    Thanks.
    ZHU

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,339 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,177 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans