D365 Business Central : Suggest Account on General Posting Setup

Have you ever found yourself scratching your head over the Suggest Account feature in the General Posting Setup? The tooltip only gives us a brief description, stating “Suggest G/L Accounts for selected setup.”. But what exactly does that mean? In this article, let’s dive into the code behind the General Posting Setup table to gain a better understanding on how this feature works.

procedure SuggestSetupAccounts()
var
    RecRef: RecordRef;
begin
    RecRef.GetTable(Rec);
    SuggestSalesAccounts(RecRef);
    SuggestPurchAccounts(RecRef);
    SuggestInvtAccounts(RecRef);
    RecRef.Modify();
end;

Looking at the above code, it will suggest Sales, Purchase, and Inventory Account on the current record.

local procedure SuggestSalesAccounts(var RecRef: RecordRef)
begin
    if "Sales Account" = '' then
        SuggestAccount(RecRef, FieldNo("Sales Account"));
    if "Sales Credit Memo Account" = '' then
        SuggestAccount(RecRef, FieldNo("Sales Credit Memo Account"));
    if "Sales Inv. Disc. Account" = '' then
        SuggestAccount(RecRef, FieldNo("Sales Inv. Disc. Account"));
    if "Sales Line Disc. Account" = '' then
        SuggestAccount(RecRef, FieldNo("Sales Line Disc. Account"));
    if "Sales Pmt. Disc. Credit Acc." = '' then
        SuggestAccount(RecRef, FieldNo("Sales Pmt. Disc. Credit Acc."));
    if "Sales Pmt. Disc. Debit Acc." = '' then
        SuggestAccount(RecRef, FieldNo("Sales Pmt. Disc. Debit Acc."));
    if "Sales Pmt. Tol. Credit Acc." = '' then
        SuggestAccount(RecRef, FieldNo("Sales Pmt. Tol. Credit Acc."));
    if "Sales Pmt. Tol. Debit Acc." = '' then
        SuggestAccount(RecRef, FieldNo("Sales Pmt. Tol. Debit Acc."));
    if "Sales Prepayments Account" = '' then
        SuggestAccount(RecRef, FieldNo("Sales Prepayments Account"));

    OnAfterSuggestSalesAccounts(Rec, RecRef);
end;

local procedure SuggestPurchAccounts(var RecRef: RecordRef)
begin
    if "Purch. Account" = '' then
        SuggestAccount(RecRef, FieldNo("Purch. Account"));
    if "Purch. Credit Memo Account" = '' then
        SuggestAccount(RecRef, FieldNo("Purch. Credit Memo Account"));
    if "Purch. Inv. Disc. Account" = '' then
        SuggestAccount(RecRef, FieldNo("Purch. Inv. Disc. Account"));
    if "Purch. Line Disc. Account" = '' then
        SuggestAccount(RecRef, FieldNo("Purch. Line Disc. Account"));
    if "Purch. Pmt. Disc. Credit Acc." = '' then
        SuggestAccount(RecRef, FieldNo("Purch. Pmt. Disc. Credit Acc."));
    if "Purch. Pmt. Disc. Debit Acc." = '' then
        SuggestAccount(RecRef, FieldNo("Purch. Pmt. Disc. Debit Acc."));
    if "Purch. Pmt. Tol. Credit Acc." = '' then
        SuggestAccount(RecRef, FieldNo("Purch. Pmt. Tol. Credit Acc."));
    if "Purch. Pmt. Tol. Debit Acc." = '' then
        SuggestAccount(RecRef, FieldNo("Purch. Pmt. Tol. Debit Acc."));
    if "Purch. Prepayments Account" = '' then
        SuggestAccount(RecRef, FieldNo("Purch. Prepayments Account"));

    OnAfterSuggestPurchAccounts(Rec, RecRef);
end;

local procedure SuggestInvtAccounts(var RecRef: RecordRef)
begin
    if "COGS Account" = '' then
        SuggestAccount(RecRef, FieldNo("COGS Account"));
    if "COGS Account (Interim)" = '' then
        SuggestAccount(RecRef, FieldNo("COGS Account (Interim)"));
    if "Inventory Adjmt. Account" = '' then
        SuggestAccount(RecRef, FieldNo("Inventory Adjmt. Account"));
    if "Invt. Accrual Acc. (Interim)" = '' then
        SuggestAccount(RecRef, FieldNo("Invt. Accrual Acc. (Interim)"));
    if "Direct Cost Applied Account" = '' then
        SuggestAccount(RecRef, FieldNo("Direct Cost Applied Account"));
    if "Overhead Applied Account" = '' then
        SuggestAccount(RecRef, FieldNo("Overhead Applied Account"));
    if "Purchase Variance Account" = '' then
        SuggestAccount(RecRef, FieldNo("Purchase Variance Account"));

    OnAfterSuggestInvtAccounts(Rec, RecRef);
end;

The suggestions for Sales, Purchase, and Inventory accounts are generated through a procedure called SuggestAccount. Let’s look at the logic inside.

protected procedure SuggestAccount(var RecRef: RecordRef; AccountFieldNo: Integer)
var
    TempAccountUseBuffer: Record "Account Use Buffer" temporary;
    RecFieldRef: FieldRef;
    GenPostingSetupRecRef: RecordRef;
    GenPostingSetupFieldRef: FieldRef;
begin
    GenPostingSetupRecRef.Open(DATABASE::"General Posting Setup");

    GenPostingSetupRecRef.Reset();
    GenPostingSetupFieldRef := GenPostingSetupRecRef.Field(FieldNo("Gen. Bus. Posting Group"));
    GenPostingSetupFieldRef.SetRange("Gen. Bus. Posting Group");
    GenPostingSetupFieldRef := GenPostingSetupRecRef.Field(FieldNo("Gen. Prod. Posting Group"));
    GenPostingSetupFieldRef.SetFilter('<>%1', "Gen. Prod. Posting Group");
    TempAccountUseBuffer.UpdateBuffer(GenPostingSetupRecRef, AccountFieldNo);

    GenPostingSetupRecRef.Reset();
    GenPostingSetupFieldRef := GenPostingSetupRecRef.Field(FieldNo("Gen. Bus. Posting Group"));
    GenPostingSetupFieldRef.SetFilter('<>%1', "Gen. Bus. Posting Group");
    GenPostingSetupFieldRef := GenPostingSetupRecRef.Field(FieldNo("Gen. Prod. Posting Group"));
    GenPostingSetupFieldRef.SetRange("Gen. Prod. Posting Group");
    TempAccountUseBuffer.UpdateBuffer(GenPostingSetupRecRef, AccountFieldNo);

    GenPostingSetupRecRef.Close();

    TempAccountUseBuffer.Reset();
    TempAccountUseBuffer.SetCurrentKey("No. of Use");
    if TempAccountUseBuffer.FindLast() then begin
        RecFieldRef := RecRef.Field(AccountFieldNo);
        RecFieldRef.Value(TempAccountUseBuffer."Account No.");
    end;
end;

The underlying logic is straightforward.
1) It will only make a suggestion if the Account No. field is blank.
2) The system will examine all other records in the General Posting Setup with the same General Business Posting Group as the current record and count the number of occurrences for each Account No.
3) Similarly, it will evaluate all records with the same General Product Posting Group as the current record.
4) The most frequently used Account No. will be suggested, and in the case of a tie, the one appearing last alphabetically will be suggested.

Let’s do a simple test. We are going to try to perform Suggest Account on INTERCOMP x RETAIL record below.

We need to pay attention to all other accounts with same General Business Posting Group – INTERCOMP (Blue Color) and same General Product Posting Group – RETAIL (Red Color).

Below is what we get for each Sales Account.
6110 x1
6130 x2
6210 x1
6410 x1
Based on the above count, the suggested Sales Account is 6130.

Below is what we get for each Sales Credit Memo Account.
6110 x1
6130 x2
6410 x2

6130 and 6410 have equal count, but because 6410 is alphabetically last, it will suggest 6410 as the Sales Credit Memo Account.

Sales Line Disc. Account and Sales Inv. Disc. Account will both have 6910.

Let’s try it and see below result.


The Suggest Account feature provides a basic suggestion for filling in the account information. It’s recommended to use this function as a starting point, then do review and make necessary adjustment.

Article inspired by Shannon question on twitter.

thatnavguy

Experienced NZ-based NAV Developer and Consultant with 15+ years of experience leading multiple IT projects, performing business analyst, developing, implementing, and upgrading Dynamics NAV and Business Central. Passionate to deliver solution that focuses on user-friendly interface while keeping high standard of compliance with the needs.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *