Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

Issue with AL Code

Posted on by 60

Hi BC Guru's,

We have some custom code written for us but unfortunately it is not working properly, and we cannot seem to find the issue. It seems that the code is always using the marketing G/L accounts regardless of the criteria. 

The criteria that must be met to use the marketing G/L is below:

The Cost of Goods Sold G/L Account Reassignment functionality uses the Return Reason code and the line amount field values specified in the Sales Line to determine if posting to the Marketing G/L Account is required. The following are the scenarios:

#1) If the good is sold for $0, and the return reason is blank, then the COG will flow through to the appropriate Market COGS G/L Account.

#2) If the good is sold for $0, and the return reason is populated with an option on the table, but it is not checked off; then it does NOT flow to the Market COGS G/L Account, and it stays in the general posting group of cost of goods. As an example, if someone receives a damaged product and we send a new one at $0, this COGS G/L Account will remain in the general posting group of cost of goods; and it would not be charged to marketing.

#3) If the good is sold for $0, and the return reason is populated with an option on the table that is checked in the box, then it does flow to the Market COGS G/L Account.

I have attached our code below:

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Inventory Posting To G/L", 'OnBeforeSetAccNo', '', true, true)]
    local procedure OnBeforeSetAccNo(var InvtPostBuf: Record "Invt. Posting Buffer"; ValueEntry: Record "Value Entry"; var IsHandled: Boolean)
    var
        lrecItem: Record Item;
        lrecItemDiscountGroup: Record "Item Discount Group";
        lrecReturnReason: Record "Return Reason";
        bMarketing: Boolean;
    begin
        bMarketing := false;
        IsHandled := false;
        if InvtPostBuf."Account Type" <> InvtPostBuf."Account Type"::COGS then
            exit;
        if ValueEntry."Return Reason Code" <> '' then
            if lrecReturnReason.Get(ValueEntry."Return Reason Code") then
                bMarketing := lrecReturnReason."INT-Marketing";

        if lrecItem.Get(ValueEntry."Item No.") then
            if lrecItem."Item Disc. Group" <> '' then
                if lrecItemDiscountGroup.Get(lrecItem."Item Disc. Group") then
                    if ((ValueEntry."Sales Amount (Actual)" = 0) and (ValueEntry."Sales Amount (Expected)" = 0)) then
                        if ((ValueEntry."Return Reason Code" = '') or ((ValueEntry."Return Reason Code" <> '') and bMarketing)) then
                            case ValueEntry."Gen. Bus. Posting Group" of
                                'GENERAL':
                                    If lrecItemDiscountGroup."INT-General G/L" <> '' then begin
                                        InvtPostBuf."Account No." := lrecItemDiscountGroup."INT-General G/L";
                                        IsHandled := true;
                                    end;
                                'INTERCO':
                                    If lrecItemDiscountGroup."INT-Intercompany G/L" <> '' then begin
                                        InvtPostBuf."Account No." := lrecItemDiscountGroup."INT-Intercompany G/L";
                                        IsHandled := true;
                                    end;
                            end;
    end;
}

  • Suggested answer
    Amit_Sharma Profile Picture
    Amit_Sharma 2,545 on at
    RE: Issue with AL Code

    Consult with your existing partner.

    Or

    contact at www.erpconsultors.com

    Regards

    Amit Sharma

  • Suggested answer
    Marco Mels Profile Picture
    Marco Mels on at
    RE: Issue with AL Code

    Hello,

    We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist. If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    www.dynamicsuser.net/.../14

    I will open this up to the community in case they have something to add.

    Thanks.

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

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans