web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

unit price missing on sales order and and how to make boolean field active inavtive according to unit price

(0) ShareShare
ReportReport
Posted on by 151

I have added field on sale prices (7002)

"Min. Price Change Allw" (decimal) and it should be less than unit price & also added same field on sales line and one more field 
"Min. Price Change Hold"; (Boolean) non editable  on sales header .
After that i have pass  data (Min. Price Change Allw")of sales prices to sales line(Min. Price Change Allw) field.
So now I want that as we select item on sales line of sales order if unit price on sales line is less than (Min. Price Change Allw) then "Min. Price Change Hold"; (Boolean) will be tick other wise it will be untick. I am able to pass data but not able to make tick untick according to unit prices
I have written some code but it does not working also I'm not able to see unit price on sales line.
code and image as below
 [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;
unit-price.png
I have the same question (0)
  • Suggested answer
    JAngle Profile Picture
    127 on at
    RE: unit price missing on sales order and and how to make boolean field active inavtive according to unit price

    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

  • Salba Z.K Profile Picture
    151 on at
    RE: unit price missing on sales order and and how to make boolean field active inavtive according to unit price

    Can u explain how code will be look like

  • Suggested answer
    Nitin Verma Profile Picture
    21,698 Moderator on at
    RE: unit price missing on sales order and and how to make boolean field active inavtive according to unit price

    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();

  • Salba Z.K Profile Picture
    151 on at
    RE: unit price missing on sales order and and how to make boolean field active inavtive according to unit price

    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

     sales-order-1.png_2D00_640x1440.png_2D00_960x534.png

    sales-prices-1.png

    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;

  • Suggested answer
    Dallefeld Profile Picture
    211 User Group Leader on at
    RE: unit price missing on sales order and and how to make boolean field active inavtive according to unit price

    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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,921

#2
YUN ZHU Profile Picture

YUN ZHU 2,012 Super User 2025 Season 2

#3
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,999 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans