web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

GL Account extraction

(0) ShareShare
ReportReport
Posted on by

Hi Guys,

I need to retrieve the GL account that is assigned to Gen. Prod. Posting Group of an Item such that when I pick Item, Fixed asset or Charge(Item) when entering a Purchase Invoice, I should get the GL account on Purch. Account.

How should I do achieve this AL or C/AL?

Kindly assist.



I have the same question (0)
  • Suggested answer
    darcnus Profile Picture
    247 on at

    I don't fully follow what you're asking - can you rephrase the questions?

    If you are looking to change which G/L your purchases map to, that would be under General Posting Setup or General Ledger Setup.

    docs.microsoft.com/.../finance-posting-groups

    If you are looking to default to the GPPG, you can set that on individual items and charges as well.

    Please reply and clarify if that doesn't answer your question.

  • Suggested answer
    JAngle Profile Picture
    135 on at

    You will need a case statement and then go to the relevant setup table with a GET or setrange and findfirst. Something like:

    Case SalesLine.Type Of

    SalesLine.Type::Item:

    Begin

     <code to get setup data>

    End;

    Etc.

    You will need variables for the setup tables. It will be based on posting groups so use the line data for that. You could do it as a calculated field page instead of being on the table unless you need it for reporting. Another pattern would be a flowfield. For either method here are some handy resources:

    www.hougaard.com/.../

    www.hougaard.com/.../

  • Community Member Profile Picture
    on at

    Hello Romryan,

    If I am following your question, you want to make sure every time that you enter/create a Purchase Invoice for an Item, Fixed Asset, or Charge(Item) the General Posting Setup/Purchasing Account is posted too. I will use the following as an example to explain the setup:

    pastedimage1608592822369v1.png

    In my screenshot above I show that when I enter a Purchase Invoice and the Vendor is Gen. Business Posting Group = DOMESTIC, an enter any Gen. Prod. Posting Group classification, my Purchase Account will = 54100, except GPPG = Raw Mat. If my Ge. Bus. Posting Group = EU then my Purchase Account = 54200, except GPPG = Raw Mat.

    As for Fixed Assets, when you select Type = Fixed Assets, on the Purchase Invoice Line, the entry does not pass through the Purchase Account but post to the FA Posting Group GL Account.

    As for the Charge(Item), this will follow the same logic as the Item, except that the Item Charge/GPPG value, which in my example = Services, will produce the Purchase Account = 54100.

    I hope the above setups explain how the Posted Purchase Invoice transaction will post to the Purchase Account for Item and Charge(Item) via the General Posting Setup (GBPG and GPPG) combination. If my understanding of your question is not correct, maybe you can write back an example.

    Thanks,

    Steve

  • Romryan Profile Picture
    on at

    Josh,

    I have reached here as per below, 

     If Type = Type::Item then
         Itm.Get("No.");
         PstGrp := Itm."Gen. Prod. Posting Group";

    Any insight on how I can now get the GL account attached to the items?

  • Suggested answer
    JAngle Profile Picture
    135 on at

                field(GLAccount; GetGLAccount())
                {
                    ApplicationArea = All;
                    Caption = 'G/L Account from Posting Group';
                }
            }
        }
        local procedure GetGLAccount(): Code[20]
        var
            GLPostingSetup: Record "General Posting Setup";
            FAPostingGroup: Record "FA Posting Group";
            FA: Record "Fixed Asset";
        begin
            case Rec.Type of
                Rec.Type::Item:
                    begin
                        If GLPostingSetup.Get(Rec."Gen. Bus. Posting Group", Rec."Gen. Prod. Posting Group") then
                            exit(GLPostingSetup."Purch. Account");
                    end;
                Rec.Type::Resource:
                    begin
                        If GLPostingSetup.Get(Rec."Gen. Bus. Posting Group", Rec."Gen. Prod. Posting Group") then
                            exit(GLPostingSetup."Purch. Account");
                    end;
                Rec.Type::"Charge (Item)":
                    begin
                        If GLPostingSetup.Get(Rec."Gen. Bus. Posting Group", Rec."Gen. Prod. Posting Group") then
                            exit(GLPostingSetup."Purch. Account");
                    end;
                Rec.Type::"Fixed Asset":
                    begin
                        If FA.Get(Rec."No.") then
                            if FAPostingGroup.get(FA."FA Posting Group") then
                                exit(FAPostingGroup."Acquisition Cost Account");
                    end;
            end;
        end;

    This is more like what you need. Most of the data is already present on the line table you just have to present it to the user. I would probably add an editable = false property just in case too. Please consider this is on the page only so you can't run a table query and get the result.

    If this answers your question please verify so others using the forum know.

  • Romryan Profile Picture
    on at

    Thank you so much Josh. I really appreciate.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,630

#2
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 800 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 789 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans