Code syntax issue on Sales Line - any help?
gadzilla1
Member Posts: 316
Newbie here,
I have a boolean field added to the Sales Line table called "Allow Volume Disc.". I want some code that applies a volume discount to execute EVERY time the boolean field is true/checked on the Sales Order, and skip every record that this field is FALSE/unchecked.
Currently everything fires great, except when there is a record in the pack that is unchecked..it applies the volume discount to the unchecked record anyway.
Here's the code I have now:
IF SalesLine2."Allow Volume Disc." THEN REPEAT
CalcVolumeDiscount(Rec);
UNTIL SalesLine2.NEXT = 0;
What needs to be changed to check for unchecked records?
Thanks for any assistance in this matter. gad1
I have a boolean field added to the Sales Line table called "Allow Volume Disc.". I want some code that applies a volume discount to execute EVERY time the boolean field is true/checked on the Sales Order, and skip every record that this field is FALSE/unchecked.
Currently everything fires great, except when there is a record in the pack that is unchecked..it applies the volume discount to the unchecked record anyway.
Here's the code I have now:
IF SalesLine2."Allow Volume Disc." THEN REPEAT
CalcVolumeDiscount(Rec);
UNTIL SalesLine2.NEXT = 0;
What needs to be changed to check for unchecked records?
Thanks for any assistance in this matter. gad1
0
Answers
-
Your code should look something like this on the validate
SalesLine2.setrange("documen type","Document type");
SalesLine2.setrange("documen No.","Document No.");
SalesLine2.setfilter("line no.",'<>%1',"Line No.");
SalesLine2.setrange("Allow Volume Disc.",true);
IF SalesLine2.find('-') THEN REPEAT
CalcVolumeDiscount(SalesLine2);
UNTIL SalesLine2.NEXT = 0;
If "Allow Volume Disc." then
CalcVolumeDiscount(Rec);0 -
Rashed,
Thanks for the tip...you say I should call your code from the on-validate...what if I'm calling the code from codeunit 414?
Will the code change?
Thanks again - gad10 -
I don't think the setfilter on the line no. is necessary..the rest seems fine..Diptish Naskar
For any queries you can also visit my blog site: http://msnavarena.blogspot.com/0 -
if you are doing it from release sales document. Then this how you would do it.
Rec is SalesHeader
SalesLine2.setrange("documen type","Document type");
SalesLine2.setrange("documen No.","No.");
SalesLine2.setrange("Allow Volume Disc.",true);
IF SalesLine2.find('-') THEN REPEAT
CalcVolumeDiscount(SalesLine2);
UNTIL SalesLine2.NEXT = 0;0 -
-
I don't know what version he is on. So always stay on safe side.0
-
-
Thanks everyone for all of your help. DenSter, Rashed, I am on version 4.01 just FYI.
I put the code in verbatim to the following. I also saw the "Rec is SalesHeader" from Rashed and understand why all of my records were calculated for a volume discount as a result...not just the 'checked' items.
I am getting the error 'The Record variable must belong to 36 and not to 37' when trying to save the changes to the Codeunit...where do I remedy this? I placed the following code in the OnRun area of Codeunit 414.
SalesLine2.setrange("document type","Document type");
SalesLine2.setrange("document No.","No.");
SalesLine2.setrange("Allow Volume Disc.",true);
IF SalesLine2.find('-') THEN REPEAT
CalcVolumeDiscount(SalesLine2);
UNTIL SalesLine2.NEXT = 0;
Once again, newbie... :roll: I'm only posting after I try to figure things out on my own and through reading the ADG.
Thanks - gad10 -
Your function CalcVolumeDiscount( is expecting a sales Header.
It does does the calculation. Can you paste that code in here?
So we can see what it's doing.0 -
Rashed - I sent a PM with the code. Thanks - gad10
-
ok got your code.
Basically you want to only calculate volume discount on lines that have the boolean checked.
To do this we have to modify the function.
So my question is do you want to include the lines in the calculation of volume discount but do not update the unit price on those sales lines?
Or just exlude them totally from the calculate?
So if you have two lines Item A qty 100, Item A qty 100. And you've setup volume discount of 150. Should the order get any volume discount if only 1st line is checked?0 -
Rashed - Thanks a ton for your help in this matter. Your questions are numbered and answered below.
1. "calculate volume discount on lines that have the boolean checked."
Yes. BUT I just talked to a customer service person and I had a major spec incorrect. The function should SUM up all quantities for all checked items and apply the discount to only the SUM of all checked items.
So, if the boolean is checked for Item A qty 100 and checked for Item B qty 100 and NOT checked for Item C qty 100...if a volume discount is set to 150, then the discount will only be applied to Item A and B.
2. "do you want to include the lines in the calculation of volume discount"
I'd like to include the lines in the calculation and NOT change the unit price...but if this is too difficult then please just leave it. The issue with having the unit price change on release of the Sales Order comes later on the Sales Invoice report where we'd like to see the change between Net and Unit price and report a discount effectively at the lines level. Right now I can't do that.
3. "So if you have two lines Item A qty 100, Item A qty 100. And you've setup volume discount of 150. Should the order get any volume discount if only 1st line is checked?"
Since the functionality should sum up only the checked item qty (see 1.) I don't think this matters anymore. There are cases where this is now valid.
My apologies for writing a dictionary.
Thanks - gad1 0 -
Ok Here is a change in code.
SalesLine2.setrange("document type","Document type");
SalesLine2.setrange("document No.","No.");
SalesLine2.setrange("Allow Volume Disc.",true);
IF SalesLine2.find('-') THEN REPEAT
CalcVolumeDiscount(Rec);
UNTIL SalesLine2.NEXT = 0;
In the function. CalcVolumeDiscount add the following line.
/update Unit Price on the lines if the Volume Discount produces a lower price.
IF TotalVolumeDiscAmount >= TotalInvoiceDiscAmount THEN BEGIN
//Mod Start
SalesLine.setrange("Allow Volume Disc.",true);
//Mod End
IF SalesLine.FINDSET(TRUE, FALSE) THEN REPEAT0 -
Rashed,
This works awesome, thank you!!! I understand the code as well.
I will put 'solved' in the title.
If you can EASILY answer the following, ok, if not please disregard.
How do I get the original unit price BACK when I reopen the order and delete some of the sales lines and the volume discount is either less or should not be applied.
Right now if the unit price is 10.00, and the discounted price is 9.00, the price stays the same when I reopen and change quantities or delete lines. When I reopen the order I want the original unit price back (10.00) and then run the function again.
Thanks - gad10 -
Code something like this will do the trick. PriceCalcMgt is CU Sales Price Calc. Mgt.
SalesLine2.reset;
SalesLine2.setrange("documen type","Document type");
SalesLine2.setrange("documen No.","No.");
IF SalesLine2.find('-') THEN REPEAT
PriceCalcMgt.FindSalesLinePrice(Rec,SalesLine2,6);
SalesLine2.VALIDATE("Unit Price");
SalesLine2.modify;
UNTIL SalesLine2.NEXT = 0;
SalesLine2.reset;
Put that before
SalesLine2.setrange("document type","Document type");
SalesLine2.setrange("document No.","No.");
SalesLine2.setrange("Allow Volume Disc.",true);
IF SalesLine2.find('-') THEN REPEAT
CalcVolumeDiscount(Rec);
UNTIL SalesLine2.NEXT = 0;
Haven't tested it. So test it beforehand.0 -
Unreal...it works very well.
=D>
Thanks - Chris0 -
You are welcome. Hope you learned enough to do your next modification.0
-
I learned a great deal. Take care - gad10
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions

