-
Notifications
You must be signed in to change notification settings - Fork 687
Description
Why do you need this change?
Please add an event publisher before the standard purchase line population logic inside the repeat loop of ApplyStdCodesToPurchaseLines. The event should include an IsHandled flag so extensions can skip the standard Purchase Line validation logic and implement custom behavior when applying Standard Vendor Purchase Codes.
Alternatives Evaluated: There are no existing events that we could use for this scenario. No event exists at the point where the Purchase Line is initialized, the standard Purchase Line context is still available, and validation has not yet occurred.
Additionally, the customization modifies or adds a custom condition to standard IF statements within the Repeat block; therefore, IsHandled is required.
Justification for IsHandled: The IsHandled flag is required because the standard logic must be bypassed entirely, not extended. Additional conditions are added in the IF statements, which need to be fully reimplemented.
Performance Considerations: The event is triggered only when: A user applies a Standard Vendor Purchase Code, The system iterates through Standard Purchase Line records, This is a user-initiated, low-frequency operation.
No additional database access is introduced by the event itself.
Expected performance impact is minimal and consistent with other IsHandled integration events in Business Central.
Data Sensitivity Review: The event exposes only Purchase Header, Purchase Line, Standard Purchase Line, Standard Purchase Code and IsHandled. These records contain, Transactional purchasing data (items, quantities, costs), no personal data, no sensitive or regulated information. There are no additional data security or privacy implications.
Multi Extension Interaction: Extensions that rely on this event must coordinate via dependency declarations. Partners can use EventSubscriberInstance = Manual to control execution order. The pattern is consistent with other core IsHandled events, so developers are familiar with the implications.
Example of our custom code:
if StdPurchLine.find('-') then
repeat
PurchLine.Init();
PurchLine."Line No." := 0;
PurchLine.Validate(Type,StdPurchLine.Type);
if StdPurchLine.Type = StdPurchLine.Type::" " then begin
PurchLine.Validate("No.",StdPurchLine."No.");
PurchLine.Description := StdPurchLine.Description;
PurchLine."Description 2" := StdPurchLine."Description 2"; //Custom Code
end else
if not StdPurchLine.EmptyLine
and not StdPurchLine.BlockedLine(StdVendPurchCode."Vendor No.") // Added additional condition
then begin
StdPurchLine.TestField("No.");
PurchLine.SuspendStatusCheck(true); //Custom Code
PurchLine.VALIDATE("No.",StdPurchLine."No.");
if StdPurchLine."Variant Code" <> '' then
PurchLine.Validate("Variant Code",StdPurchLine."Variant Code");
if PurchLine.Quantity <> StdPurchLine.Quantity then //Custom if condition
PurchLine.Validate(Quantity,StdPurchLine.Quantity);
//if StdPurchLine."Unit of Measure Code" <> '' then //Standard code we don't need
// PurchLine.VALIDATE("Unit of Measure Code",StdPurchLine."Unit of Measure Code"); //Standard code we don't need
PurchLine.Description := StdPurchLine.Description;
PurchLine."Description 2" := StdPurchLine."Description 2"; // Custom code
if (StdPurchLine.Type = StdPurchLine.Type::"G/L Account") or
(StdPurchLine.Type = StdPurchLine.Type::"Charge (Item)")
then
PurchLine.Validate(
"Direct Unit Cost",
Round(StdPurchLine."Amount Excl. VAT" *
(PurchLine."VAT %" / 100 * Factor + 1),Currency."Unit-Amount Rounding Precision"));
end;Describe the request
procedure ApplyStdCodesToPurchaseLines(PurchHeader: Record "Purchase Header"; StdVendPurchCode: Record "Standard Vendor Purchase Code")
var
...
IsHandled: Boolean; //Additional new local variable
begin
PurchLine.LockTable();
StdPurchLine.LockTable();
if StdPurchLine.Find('-') then
repeat
PurchLine.Init();
PurchLine.SetPurchHeader(PurchHeader);
PurchLine."Line No." := 0;
PurchLine.Validate(Type, StdPurchLine.Type);
//>> Code change starts
OnRepeatOnApplyStdCodesToPurchaseLines(Rec, StdPurchLine, PurchLine, PurchHeader, StdPurchCode, IsHandled)
if not IsHandled then begin
if StdPurchLine.Type = StdPurchLine.Type::" " then begin
PurchLine.Validate("No.", StdPurchLine."No.");
PurchLine.Description := StdPurchLine.Description;
PurchLine."Buy-from Vendor No." := PurchHeader."Buy-from Vendor No.";
end else
if not StdPurchLine.EmptyLine() then begin
StdPurchLine.TestField("No.");
PurchLine.Validate("No.", StdPurchLine."No.");
if StdPurchLine."Variant Code" <> '' then
PurchLine.Validate("Variant Code", StdPurchLine."Variant Code");
PurchLine.Validate(Quantity, StdPurchLine.Quantity);
if StdPurchLine."Unit of Measure Code" <> '' then
PurchLine.Validate("Unit of Measure Code", StdPurchLine."Unit of Measure Code");
if StdPurchLine.Description <> '' then
PurchLine.Validate(Description, StdPurchLine.Description);
if (StdPurchLine.Type = StdPurchLine.Type::"G/L Account") or
(StdPurchLine.Type = StdPurchLine.Type::"Charge (Item)") then
PurchLine.Validate(
"Direct Unit Cost",
Round(StdPurchLine."Amount Excl. VAT" *
(PurchLine."VAT %" / 100 * Factor + 1), Currency."Unit-Amount Rounding Precision"));
end
end;
//>> Code change ends
PurchLine."Shortcut Dimension 1 Code" := StdPurchLine."Shortcut Dimension 1 Code";
PurchLine."Shortcut Dimension 2 Code" := StdPurchLine."Shortcut Dimension 2 Code";
...
end;
[IntegrationEvent(false, false)]
local procedure OnRepeatOnApplyStdCodesToPurchaseLines(var StdVendPurchCode: Record "Standard Vendor Purchase Code"; var StdPurchLine: Record "Standard Purchase Line"; var PurchLine: Record "Purchase Line"; var PurchHeader: Record "Purchase Header"; var StdPurchCode: Record "Standard Purchase Code"; var IsHandled: Boolean)
begin
end;