Dynamics 365 Business Central: How to set default Account type in General Journals (Customization)

Dynamics 365 Business Central

Hi, Readers.
Today I would like to talk about a simple customization, how to set default Account type in General Journals in Business Central.

As you might know, sales and purchase documents can contain different types of lines, such as G/L Account, Item, Resource, or Fixed Asset. In Business Central 2021 wave 2 (BC19), Microsoft add a new feautre, we can select the default line type that will be suggested when we create new documents. More details: Link.

It is very great.
Recently I saw a question, can we set default Account Type in General Journals?

Unfortunately, Microsoft has not added this feature yet. Generally, when opening the General Journals page or inserting a new line, the first one in Enum is displayed (‘G/L Account’).

So how is it done if we want to customize it?

There are mainly two solutions for this. One is to control the default value through the field in the General Ledger Setup, just like sales and purchase documents. Another is to add a default Account type in General Journal Batches. Personally, I prefer the latter. Let’s try it together.

Solution 1

1. Add Default Journal Account Type field to General Ledger Setup table and display it on the page.

2. Then add logic to the OnNewRecord trigger of General Journal page.

Test Video:

Source Code:

pageextension 50110 ZYGeneralJournalExt extends "General Journal"
{
    trigger OnNewRecord(BelowxRec: Boolean)
    begin
        SetDefaultType();
    end;

    local procedure SetDefaultType()
    begin
        Rec."Account Type" := GetDefaultLineType();
    end;

    procedure GetDefaultLineType(): Enum "Gen. Journal Account Type"
    begin
        if GenLedgerSetup.Get() then
            exit(GenLedgerSetup."ZY Def Journal Account Type");
    end;

    var

        GenLedgerSetup: Record "General Ledger Setup";
}

tableextension 50111 ZYGeneralLedgerSetupExt extends "General Ledger Setup"
{
    fields
    {
        field(50000; "ZY Def Journal Account Type"; Enum "Gen. Journal Account Type")
        {
            Caption = 'Default Journal Account Type';
            DataClassification = CustomerContent;
        }
    }
}

pageextension 50111 ZYGeneralLedgerSetupExt extends "General Ledger Setup"
{
    layout
    {
        addafter("Bank Account Nos.")
        {
            field("ZY Default Account Type"; Rec."ZY Def Journal Account Type")
            {
                ApplicationArea = All;
            }
        }
    }
}

Solution 2

1. Add Default Journal Account Type field to Gen. Journal Batch table and display it on the page.

2. Then add logic to the OnNewRecord trigger of General Journal page.

Test Video:

Source Code:

pageextension 50110 ZYGeneralJournalExt extends "General Journal"
{
    trigger OnNewRecord(BelowxRec: Boolean)
    begin
        SetDefaultType();
    end;

    local procedure SetDefaultType()
    begin
        Rec."Account Type" := GetDefaultLineType();
    end;

    procedure GetDefaultLineType(): Enum "Gen. Journal Account Type"
    var
        GenJournalBatch: Record "Gen. Journal Batch";
    begin
        if GenJournalBatch.Get(Rec."Journal Template Name", Rec."Journal Batch Name") then
            exit(GenJournalBatch."ZY Def Journal Account Type");
    end;
}

tableextension 50111 ZYGenJournalBatchExt extends "Gen. Journal Batch"
{
    fields
    {
        field(50000; "ZY Def Journal Account Type"; Enum "Gen. Journal Account Type")
        {
            Caption = 'Default Journal Account Type';
            DataClassification = CustomerContent;
        }
    }
}

pageextension 50111 ZYGeneralJournalBatchesExt extends "General Journal Batches"
{
    layout
    {
        addafter("Bal. Account No.")
        {
            field("ZY Default Account Type"; Rec."ZY Def Journal Account Type")
            {
                ApplicationArea = All;
            }
        }
    }
}

Isn’t it very easy? Give it a try!!!😁

PS: This method also works for pages like Cash Receipt Journals, Payment Journals, etc.

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL