Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Answered

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

Posted on by 127

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
Categories:
  • Suggested answer
    Dallefeld Profile Picture
    Dallefeld 11,423 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.

  • Salba Z.K Profile Picture
    Salba Z.K 127 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
    Nitin Verma Profile Picture
    Nitin Verma 21,023 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
    Salba Z.K 127 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
    JAngle Profile Picture
    JAngle 33,155 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

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,537 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,520 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans