ALAppExtensions icon indicating copy to clipboard operation
ALAppExtensions copied to clipboard

[Event Request] Record::"Sales Line" - Function InitHeaderDefaults OnBeforeInitHeaderDefaults

Open SWE-Tina opened this issue 6 years ago • 7 comments

As we have some Testfields we need something like "OnBeforeInitHeaderDefaults" as testing of required information after already having assigned values would lead to inappropriate data or to needless deletion after setting data.

SWE-Tina avatar Nov 02 '20 12:11 SWE-Tina

Hi @SWE-Tina . Please provide needed event signature and its placement in the code.

RomanZanizdra avatar Nov 06 '20 18:11 RomanZanizdra

Placement in code: between "System-Created Entry" := TempSalesLine."System-Created Entry"; and GetSalesHeader(); in OnValidate of "No.".

Signature: local procedure "Sales Line_SalesLine:OnBeforeInitHeaderDefaults"(Record "Sales Line"; SalesHeader: Record "Sales Header")

SWE-Tina avatar Nov 09 '20 08:11 SWE-Tina

Hi @SWE-Tina .

                OnValidateNoOnCopyFromTempSalesLine(Rec, TempSalesLine, xRec);
                if "No." = '' then
                    exit;

                if HasTypeToFillMandatoryFields() then
                    Quantity := TempSalesLine.Quantity;

                "System-Created Entry" := TempSalesLine."System-Created Entry";
                GetSalesHeader();
                InitHeaderDefaults(SalesHeader);
                OnValidateNoOnAfterInitHeaderDefaults(SalesHeader, TempSalesLine);

There are couple of existing events nearby. Does, for example, OnValidateNoOnCopyFromTempSalesLine fit to your need?

RomanZanizdra avatar Nov 09 '20 10:11 RomanZanizdra

I thought about it, too - but I came to the conclusion that it would just be a workaround as it is related to Sales Header and the InitHeaderDefaults. It would not be the events I'd look at first to see the code and in case some other code will be added in between, it will move more and more away from the actual point. So, yes, it is somehow possible but it would be more structured to have an event at that point and the Testfield is just necessary in case "No." is <> '' for example and therefore it's even safer to have checkings regarding that after that point.

SWE-Tina avatar Nov 09 '20 10:11 SWE-Tina

You can check condition "No." is <> '' inside the OnValidateNoOnCopyFromTempSalesLine. Do you have any other issues using it? If yes, please provide the scenario.

RomanZanizdra avatar Nov 09 '20 12:11 RomanZanizdra

I know, but first of all this is redundant code, what is one thing we try to avoid. Second, it does not belong to that regarding the topic. No one will have a look in this subscriber by first idea. As soon as there will be some more code in between, it will become more and more unclear. It's a matter of having the right structure to have consistent and understandable code. But anyways, I'll leave comments in the table extension and all events around that coding where to find the checkings, to ensure people find it / think about it.

SWE-Tina avatar Nov 20 '20 13:11 SWE-Tina

Thanks for reporting this. We agree, and we’ll publish a fix asap, either in an update for the current version or in the next major release. We will update this issue with information about availability. Please do not reply to this, as we do not monitor closed issues. If you have follow-up questions or requests, please create a new issue where you reference this one.

JesperSchulz avatar Dec 09 '20 12:12 JesperSchulz