microsoft / ALAppExtensions

Repository for collaboration on Microsoft AL application add-on and localization extensions for Microsoft Dynamics 365 Business Central.
MIT License
748 stars 600 forks source link

[Event Request] - Table Sales Line - Function InitDeferralCode #26784

Open DanielHaglo opened 5 days ago

DanielHaglo commented 5 days ago

Describe the request

    local procedure InitDeferralCode()
    var
        Item: Record Item;
        IsHandled: Boolean;
        ShouldUpdateDeferralCode: Boolean;
    begin
        IsHandled := false;
        OnBeforeInitDeferralCode(Rec, IsHandled);
        if IsHandled then
            exit;

       ShouldUpdateDeferralCode := SalesLine."Document Type" in [SalesLine."Document Type"::Order, SalesLine."Document Type"::Invoice, SalesLine."Document Type"::"Credit Memo", SalesLine."Document Type"::"Return Order"];
        OnBeforeUpdateDeferralCode(SalesLine, ShouldUpdateDeferralCode);
        if ShouldUpdateDeferralCode then
            case Type of
                Type::"G/L Account":
                    Validate("Deferral Code", GLAcc."Default Deferral Template Code");
                Type::Item:
                    begin
                        GetItem(Item);
                        Validate("Deferral Code", Item."Default Deferral Template Code");
                    end;
                Type::Resource:
                    Validate("Deferral Code", Res."Default Deferral Template Code");
            end;
    end;

Additional context

Could this function be made like this?

I need this because i want to also set the deferral code when the document type is quote. I know i can use the onbeforeinitdeferralcode, but i thought it would be smoother with event OnBeforeUpdateDeferralCode