Skip to main content
Answered

check condition for each line of sales line

editSubscribe (0) ShareShare
ReportReport
Posted on by 127

i have added one field on price list line and sales line and one Boolean field on sales header.

If unit price<min price then header field is true i have written code as below and it is working  but problem is it is not checking all line of sales line.If there is any single line with unit price less than min price then Boolean field must be true always. 

[EventSubscriber(ObjectType::Table, Database::"Sales Line", 'OnAfterGetSalesHeader', '', true, true)]
    local procedure MyProcedure(var SalesLine: Record "Sales Line"; var SalesHeader: Record "Sales Header"; var Currency: Record Currency)
    var
        PriceList: Record "Price List Line";
    begin
        PriceList.Reset();
        PriceList.SetRange("Asset No.", SalesLine."No.");
        if PriceList.FindSet(true, true) then
            repeat
                if not salesHeader.get(SalesLine."Document Type", SalesLine."Document No.") then
                    exit;
                if (PriceList."Min. Price Change Allw" > SalesLine."Unit Price") then

                    salesHeader."Min. Price Change Hold" := true
                    else
                          salesHeader."Min. Price Change Hold" := false;


           
            until
               SalesLine.Next() = 0;
        SalesHeader.Modify()



       

    end;