Get last record stopped record

catiamatos1991
Member Posts: 158
I have this dataport in nav 2009 and for new records in Sales Price table it isn't filling the field "Ending Date". I've the code (Findfirst) to that and with my debug it doens't enter there, even with a record

My text file
1510300131 06-11-18 0 4,66
(itemno, starting date, quantity, price)
I've also tried this in OnInsert Sales Price trigger

Sales Price - OnAfterImportRecord() "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("Starting Date",DATAINI); "Sales Price".SETRANGE("Currency Code",''); "Sales Price".SETRANGE("Variant Code",''); "Sales Price".SETRANGE("Unit of Measure Code",''); "Sales Price".SETRANGE("Minimum Quantity",QT); "Sales Price".DELETEALL; "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("Ending Date",0D); "Sales Price".SETRANGE("Currency Code",''); "Sales Price".SETRANGE("Variant Code",''); "Sales Price".SETRANGE("Unit of Measure Code",''); "Sales Price".SETRANGE("Minimum Quantity",QT); IF "Sales Price".FINDFIRST THEN BEGIN IF DATAINI< "Sales Price"."Starting Date" THEN "Sales Price".DELETEALL; END; "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("Ending Date",0D); "Sales Price".SETRANGE("Currency Code",''); "Sales Price".SETRANGE("Variant Code",''); "Sales Price".SETRANGE("Unit of Measure Code",''); "Sales Price".SETRANGE("Minimum Quantity",QT); IF "Sales Price".FINDFIRST THEN BEGIN "Sales Price"."Ending Date":=DATAINI-1; MODIFY; END; "Sales Price".RESET; "Sales Price"."User ID":=USERID; "Sales Price"."Data criacao":=TODAY; "Sales Price"."Ending Date":=0D; "Sales Price"."Sales Type":=1; VALIDATE("Sales Code",'ALL'); "Item No.":=PRODUTO; "Starting Date":=DATAINI; "Minimum Quantity":=QT; "Sales Price"."Allow Invoice Disc." :=TRUE; "Sales Price"."VAT Bus. Posting Gr. (Price)":='NAC'; "Sales Price"."Allow Invoice Disc.":=TRUE; VALIDATE("Unit Price",PVP); // "Sales Price".INSERT;
My text file
1510300131 06-11-18 0 4,66
(itemno, starting date, quantity, price)
I've also tried this in OnInsert Sales Price trigger
IF xRec."Item No."<>'' THEN BEGIN Rec."Ending Date":=xRec."Starting Date"-1; MODIFY; END;
0
Answers
-
catiamatos1991 wrote: »Rec."Ending Date":=xRec."Starting Date"-1;
I don't see if it's a date something like that could work. You should use calcdate instead:
https://docs.microsoft.com/en-us/dynamics-nav/calcdate-function--date-
0 -
The problem itself is to don't fill this field sometimes and I can't figure why0
-
I would set a filter for "Starting Date" and then modify all found records, not just the first one
... "Sales Price".SETRANGE("Unit of Measure Code",''); "Sales Price".SETRANGE("Minimum Quantity",QT); // IF "Sales Price".FINDFIRST THEN BEGIN // "Sales Price"."Ending Date":=DATAINI-1; // MODIFY; // END; "Sales Price".SETFILTER("Starting Date",'<%1',DATAINI); "Sales Price".MODIFYALL("Ending Date",DATAINI-1,TRUE) ...
... also, if the quantity scale changes, you might be in trouble. But it is a tricky business to import prices unless what you import replaces what you already have entirely.0 -
I'm using a dataport understand? And I can't figure where to put the Ending Date calc (In a aftergetrecord trigger maybe).
I tried to put a message in the "find last" function but it doens't pop up for some reason, and in this specific produtct I have multiple Sales Line lines.
In the image below I have the text file i'm trying to import and the final result
0 -
You filter on
"Sales Price".SETRANGE("Unit of Measure Code",'');
but the "Unit of Measure Code" of your old sales price line is UNI, and there is no unit of measure in your input file. So why do you expect to get a result different from what you got?
The trigger you used, according to your first post, is ok (assuming that data item processes the import data).0 -
I understand @vaprog but my confusion is that this code, once worked in the past without any problems and also filled automatically the unit of measure code...
So I need to remove all code from the dataport which don't exist in the text file? I'm confused0
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