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
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.
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.
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
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.
Hi
Can u pls guide how it can be done. and where is the code to be written
Thanks
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.
Sohail Ahmed
2
mmv
2
Amol Salvi
2