Announcements
I have added field on sale prices (7002)
[EventSubscriber(ObjectType::Table, Database::"Sales Line", 'OnAfterValidateEvent', 'No.', true, true)] local procedure MinChangedAllowed(var Rec: Record "Sales Line"; var xRec: Record "Sales Line") var "Sales Price": Record "Sales Price"; salesHeader: record "Sales Header"; begin "Sales Price".SetRange("Item No.", Rec."No."); if "Sales Price".FindSet() then begin Rec."Min. Price Change Allowed" := "Sales Price"."Min. Price Change Allw"; end; if "Sales Price"."Unit Price" < Rec."Min. Price Change Allowed" then salesHeader."Min. Price Change Hold" := true else salesHeader."Min. Price Change Hold" := false; end;
the problem with the above code, is that the salesheader can be changed to true and then subsequently changed to false based on the order of price changes that are done.
Suggest adding a test for salesheader.'min. price change hold' = false, just after the if not/exit statement and place the next two if statements within a begin/end qualifier.
hi Nitin thanks actually I want (the minimum price change hold on sales header get active if someone change(or default) unit price excl vat on sales line is less than the min price change allowed on sales line otherwise "Min. Price Change Hold" := false; is false.) I have tried your code but it does not work
it will be great thank if u can help doing thius
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales Line - Price", 'OnAfterSetPrice', '', false, false)] local procedure OnAfterSetPrice(var SalesLine: Record "Sales Line"; PriceListLine: Record "Price List Line"; AmountType: Enum "Price Amount Type") var salesHeader: record "Sales Header"; begin if not salesHeader.get(SalesLine."Document Type", SalesLine."Document No.") then exit; if PriceListLine."Unit Price" <= SalesLine."Min. Price Change Allowed" then salesHeader."Min. Price Change Hold" := true; if PriceListLine."Unit Price" > SalesLine."Min. Price Change Allowed" then salesHeader."Min. Price Change Hold" := false; salesHeader.Modify(); end;
Hi Salba Z.K ,
can you please check if the new sales price is enabled by going to Feature management? and then please replace your code as per below
Below is suitable event, but condition I put might be wrong please correct them accordingly.
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales Line - Price", 'OnAfterSetPrice', '', false, false)]
local procedure OnAfterSetPrice(var SalesLine: Record "Sales Line"; PriceListLine: Record "Price List Line"; AmountType: Enum "Price Amount Type")
var
salesHeader: record "Sales Header";
begin
if not salesHeader.get(SalesLine."Document Type", SalesLine."Document No.") then
exit;
if PriceListLine."Unit Price" > SalesLine."Unit Price" then
salesHeader."Min. Price Change Hold" := true;
if PriceListLine."Unit Price" < SalesLine."Unit Price" then
salesHeader."Min. Price Change Hold" := false;
salesHeader.Modify();
Can u explain how code will be look like
The sales header doesn’t target the record. Surely you should set the minimum price when the sales price is added to the sales line. I’d probably move the event to be on release of the order given you only need 1 line to make the header Boolean true. Seems pointless triggering it for every line
André Arnaud de Cal... 291,359 Super User 2024 Season 2
Martin Dráb 230,370 Most Valuable Professional
nmaenpaa 101,156