Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Sales Line

(0) ShareShare
ReportReport
Posted on by 3,099

Hi

  I want in Sales Line if there is discount in any line then Discount field should not be empty in any line. If it is empty message should be displayed when user Saves the record.

Thanks

*This post is locked for comments

  • Verified answer
    Suresh Kulla Profile Picture
    47,789 on at
    RE: Sales Line

    You need to call this function in the PerformManualRelease function, it will not be called automatically and the code should like this

    If you want to execute this function only for orders so your first statement should be

    IF SalesHeader."Document Type" <> SalesHeader."Document Type"::Order THEN

     EXIT

    SalesLine.RESET;

    SalesLine.SETRANGE("Document Type",SalesHeader."Document Type");

    SalesLine.SETRANGE("Document No.",SalesHeader."No.");

    SalesLine.SETRANGE(Type,SalesLine.Type::Item);

    SalesLine.SETFILTER("Line Discount",'>%1',0);

    IF SalesLine.FINDFIRST THEN BEGIN

      SalesLine.SETRANGE("Line Discount",0);

      IF SalesLine.FINDFIRST THEN

          ERROR('SalesLine %1 does not have any discounts',SalesLine."Line No.");

    END;

    This way the function first will check if there are lines with discount defined and if so it will check if there are any other lines with discount 0 if so then throw an error.

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at
    RE: Sales Line

    Regarding your last post:

    1) add also filter for Document Type = Order

    2) a code in function inside a codeunit must be called when you need it. Codeunits are not automatically executed by the system.

  • jsshivalik Profile Picture
    3,099 on at
    RE: Sales Line

    Hi

      I am trying like this . is it ok

    IsDiscountExists(SaleHead : Record "Sales Header")
    SLine.RESET;
    SLine.SETRANGE(SLine."No.",SaleHeadSaleHeadSaleHead."No.");
    Sline.SETFILTER(SLine."Line Discount %",>%1',0);
    IF SLine.FINDFIRST THEN BEGIN
    message('%1','Discount Exists');
    End;

    Secondly i want to know that in Codeunit every function will automatically gets executed or it is to be called

    Thanks

  • Verified answer
    nav.mukesh Profile Picture
    619 on at
    RE: Sales Line

    Hi,

    You need to write the code in CU 414 which is executed when the user click on Release button on Sales Order. You can create a function IsSalesLineWithDiscExist to check if there is a line with Disc, create one more function IsSalesLineWithNoDiscExist to check if there is a line with No Disc. if Yes, throw the error.

    If IsSalesLineWithDiscExist Then

     If IsSalesLineWithNoDiscExist Then

       Error('....');

    I could have provided you the code but then that would take away the opportunity from you to explore the NAV Standard Code flow. More you will debug, more you will learn.  Please debug and try to write the code. If you still get stuck, please share the code written and I would be happy to help.

  • jsshivalik Profile Picture
    3,099 on at
    RE: Sales Line

    Hi

      Can u pls guide how it can be done. and where is the code to be written

    Thanks

  • Suggested answer
    nav.mukesh Profile Picture
    619 on at
    RE: Sales Line

    Rather than putting the validation on saving the record, you should put it on Release Order activity. Putting it on saving the record will be confusing to you as well as user.

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Microsoft Dynamics NAV (Archived)

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2

#1
mmv Profile Picture

mmv 2

#1
Amol Salvi Profile Picture

Amol Salvi 2

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans