Findlast not getting the correct record

catiamatos1991
Member Posts: 158
So I need to change my previous record (if it exists) of Sales Price.
When I insert a new record I need to fill the "Ending Date" field.
But my problem now is I tried this code
But the previous record is not being modified... And the message shows the a wrong previous record like the image below...

I need to fill the field Ending Date right next to the date 08-11-2018 to close the last product price. In this case it should have the value (12-11-2018) but is not being filled for some reason.
My idea is when inserting a new record I always need to fill the Ending Date of my previous record. If I'm modifying a record already inserted in the system, the idea is to modify the existing record understand?
When I insert a new record I need to fill the "Ending Date" field.
But my problem now is I tried this code
IF "Sales Price".INSERT(TRUE) THEN BEGIN "Sales Price".RESET; IF "Sales Price".FINDLAST THEN BEGIN "Sales Price".NEXT(-1); MESSAGE('data 2 %1 ',"Sales Price"."Starting Date"); "Sales Price"."Ending Date":=DataInicio-1; "Sales Price".MODIFY(TRUE); END;
But the previous record is not being modified... And the message shows the a wrong previous record like the image below...

I need to fill the field Ending Date right next to the date 08-11-2018 to close the last product price. In this case it should have the value (12-11-2018) but is not being filled for some reason.
My idea is when inserting a new record I always need to fill the Ending Date of my previous record. If I'm modifying a record already inserted in the system, the idea is to modify the existing record understand?
0
Answers
-
Instead of going previous record the better way is to find the sales price again with new instance and then update the ending date.
you could do
if salesprice.insert then
salespriceenddate.setfilters (new instance of sales price table- set the filters to get the line where you want to update the ending date)
if salespriceenddate.findfirst then
salespriceenddate.ending date:=DataInicio-1;
salespriceenddate.modify
United Kingdom0 -
My confusion is how I'm going to pass the filter I'm going to pass? I can't get the right last Starting Date with find last...
0 -
sorry:
if salesprice.insert then
salespriceenddate.setfilters (new instance of sales price table- set the filters to get the line where you want to update the ending date)
if salespriceenddate.findlast then
salespriceenddate.ending date:=DataInicio-1;
salespriceenddate.modify
pass the ending date not blank filter
United Kingdom0 -
My problem is I can't get the previous line to change to set the filter. I understand your code0
-
dont find the previous line. filter the table as you would do from the start. I do not understand where the issue is.United Kingdom0
-
IF "Sales Price".INSERT(TRUE) THEN BEGIN "Sales Price".RESET; "Sales Price".SETRANGE("Sales Price"."Item No.",PRODUTO); "Sales Price".SETRANGE("Sales Price"."Sales Type",1); "Sales Price".SETRANGE("Sales Price"."Sales Code",'ALL'); "Sales Price".SETRANGE("Sales Price"."VAT Bus. Posting Gr. (Price)",'NAC'); "Sales Price".SETRANGE("Ending Date",0D); "Sales Price".SETRANGE("Currency Code",''); "Sales Price".SETRANGE("Variant Code",''); IF "Sales Price".FINDLAST THEN BEGIN MESSAGE('data 1 %1 ',"Sales Price"."Starting Date"); "Sales Price"."Ending Date":=DataInicio-1; "Sales Price".MODIFY(TRUE); END; END ELSE BEGIN "Sales Price".MODIFY(TRUE); END;
This will fill the Ending Date of my current Line and not the previous one.. SO the price instead of 10.95 should be 12.65 (unit Price)
0 -
Just add another filter on Setfilter (starting date, <>%1 , sales price."starting date")United Kingdom0
-
I've used this and worked.. What you think? Is not a right way? I Know that i want always the previous line of what i'm inserting so I add this "Sales Price".NEXT(-1); to my code
IF "Sales Price".INSERT(TRUE) THEN BEGIN "Sales Price".RESET; "Sales Price".SETRANGE("Sales Price"."Item No.",PRODUTO); "Sales Price".SETRANGE("Sales Price"."Sales Type",1); "Sales Price".SETRANGE("Sales Price"."Sales Code",'ALL'); "Sales Price".SETRANGE("Sales Price"."VAT Bus. Posting Gr. (Price)",'NAC'); "Sales Price".SETRANGE("Ending Date",0D); "Sales Price".SETRANGE("Currency Code",''); "Sales Price".SETRANGE("Variant Code",''); IF "Sales Price".FINDLAST THEN BEGIN MESSAGE('data 1 %1 ',"Sales Price"."Starting Date"); "Sales Price".NEXT(-1); "Sales Price"."Ending Date":=DataInicio-1; "Sales Price".MODIFY(TRUE); END; END ELSE BEGIN "Sales Price".MODIFY(TRUE); END;
And worked...
0 -
by the way i would have done different , i would have closed the last active sales price line and then insert the new priceUnited Kingdom0
-
BUt i've dont what you said,
if salesprice.insert then salespriceenddate.setfilters (new instance of sales price table- set the filters to get the line where you want to update the ending date) if salespriceenddate.findlast then salespriceenddate.ending date:=DataInicio-1; salespriceenddate.modify
0 -
thats fine if worked i was just only wanted to work for you what you already had started but if i was doing this i would have closed the sales price first and then insert new price.United Kingdom0
-
Hmm ok, thanks for the idea though0
-
[Topic moved from 'NAV/Navision Classic Client' forum to 'NAV Three Tier' forum]
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
Use SETCURRENTKEY You will get the record that you expecting!!Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/1 -
yes you are correctUnited Kingdom0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K 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
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions