ALAppExtensions icon indicating copy to clipboard operation
ALAppExtensions copied to clipboard

[Event Request] Table 39- "Purchase Line" - OnValidate "Unit of Measure Code" - OnValidateUnitOfMeasureCodeOnBeforeGetUnitOfMeasure

Open UIBKH opened this issue 3 years ago • 1 comments

Dear Support,

We would like to add a new event OnValidateUnitOfMeasureCodeOnBeforeGetUnitOfMeasure in the following trigger using the IsHandled pattern. This would allow us to further customize the code and migrate existing customizations.


 trigger OnValidate()
 var
     Item: Record Item;
     UnitOfMeasureTranslation: Record "Unit of Measure Translation";
     Resource: Record Resource;
     IsHandled: Boolean;
     ShouldUpdateItemReference: Boolean;
 begin
     TestStatusOpen();
     TestField("Quantity Received", 0);
     TestField("Qty. Received (Base)", 0);
     TestField("Qty. Rcd. Not Invoiced", 0);
     TestField("Return Qty. Shipped", 0);
     TestField("Return Qty. Shipped (Base)", 0);
     if "Unit of Measure Code" <> xRec."Unit of Measure Code" then begin
         TestField("Receipt No.", '');
         TestField("Return Shipment No.", '');
     end;

     IsHandled := false;
     OnValidateUnitOfMeasureCodeOnBeforeDropShipmentError(Rec, IsHandled, xRec, CurrFieldNo);
     if not IsHandled then
         if "Drop Shipment" then
             Error(Text001, FieldCaption("Unit of Measure Code"), "Sales Order No.");

     if (xRec."Unit of Measure Code" <> "Unit of Measure Code") and (Quantity <> 0) then begin
         WhseValidateSourceLine.PurchaseLineVerifyChange(Rec, xRec);
         PlanPriceCalcByField(FieldNo("Unit of Measure Code"));
     end;
     //New  Code --
     IsHandled := false;
     OnValidateUnitOfMeasureCodeOnBeforeGetUnitOfMeasure(Rec, IsHandled); //New  Code --++
     if not IsHandled then 
     //New  Code ++
         if "Unit of Measure Code" = '' then
             "Unit of Measure" := ''
         else begin
             UnitOfMeasure.Get("Unit of Measure Code");
             "Unit of Measure" := UnitOfMeasure.Description;
             GetPurchHeader();
             if PurchHeader."Language Code" <> '' then begin
                 UnitOfMeasureTranslation.SetRange(Code, "Unit of Measure Code");
                 UnitOfMeasureTranslation.SetRange("Language Code", PurchHeader."Language Code");
                 if UnitOfMeasureTranslation.FindFirst() then
                     "Unit of Measure" := UnitOfMeasureTranslation.Description;
             end;
         end;
     ShouldUpdateItemReference := Type = Type::Item;
     OnValidateUnitOfMeasureCodeOnAfterCalcShouldUpdateItemReference(Rec, ShouldUpdateItemReference);
     if ShouldUpdateItemReference then
         UpdateItemReference();
     if "Prod. Order No." = '' then
         case Type of
             Type::Item:
                 begin
                     GetItem(Item);
                     AssignFieldsForQtyPerUOM(Item, CurrFieldNo);

                     OnAfterAssignItemUOM(Rec, Item, CurrFieldNo);
                     if "Qty. per Unit of Measure" > xRec."Qty. per Unit of Measure" then
                         InitItemAppl();

                     UpdateUOMQtyPerStockQty();
                 end;
             Type::Resource:
                 begin
                     GetResource(Resource);
                     "Qty. per Unit of Measure" := UoMMgt.GetResQtyPerUnitOfMeasure(Resource, "Unit of Measure Code");
                     OnAfterAssignResourceUOM(Rec, Resource, CurrFieldNo);
                     if "Unit of Measure Code" <> xRec."Unit of Measure Code" then
                         PlanPriceCalcByField(FieldNo("Unit of Measure Code"));
                 end;
             Type::" ",
             Type::"Charge (Item)",
             Type::"Fixed Asset",
             Type::"G/L Account":
                 "Qty. per Unit of Measure" := 1;
         end
     else
         "Qty. per Unit of Measure" := 0;

     OnValidateUnitOfMeasureCodeOnBeforeValidateQuantity(Rec, xRec, Item);
     Validate(Quantity);
     UpdateDirectUnitCostByField(FieldNo("Unit of Measure Code"));
 end;

Event Signature:

    [IntegrationEvent(false, false)]
    local procedure OnValidateUnitOfMeasureCodeOnBeforeGetUnitOfMeasure(var PurchaseLine: Record "Purchase Line"; var IsHandled: Boolean)
    begin
    end;

UIBKH avatar Feb 15 '23 08:02 UIBKH

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. 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.

Build ID: 53447.

JesperSchulz avatar Feb 21 '23 10:02 JesperSchulz