Can't get last record of Sales Price

catiamatos1991
Member Posts: 158
Hi everyone,
I've created a xmlport to import a text file and fill the Sales Price table.
The problem is when I import the file for the first time it creates a new line in Sales Price table. But if the user for some reason wants to upload the same file (with the same info or anything different than the Starting Date) it will modify the last existing record.
If i want to upload a new line which doesnt exist in the Sales Price table I need to fill the "Ending Date" field but somehow with this code "IF "Sales Price".FINDLAST" it doenst do anything.
My code:
My text file
where the first column is ITEM_No, the second is the Starting Date, the third is quantity and the last column is the price.
For some reason is not poping the message ("begin2") which means that this condition IF "Sales Price".FINDLAST THEN BEGIN is not being verified.
My table have a few rows and I don't know why he can't get the last record.
All the code of xmlport is here below,
I've created a xmlport to import a text file and fill the Sales Price table.
The problem is when I import the file for the first time it creates a new line in Sales Price table. But if the user for some reason wants to upload the same file (with the same info or anything different than the Starting Date) it will modify the last existing record.
If i want to upload a new line which doesnt exist in the Sales Price table I need to fill the "Ending Date" field but somehow with this code "IF "Sales Price".FINDLAST" it doenst do anything.
My code:
IF NOT "Sales Price".INSERT(TRUE) THEN BEGIN MESSAGE('begin1'); MESSAGE('check %1',"Sales Price".FINDLAST); IF "Sales Price".FINDLAST THEN BEGIN MESSAGE('begin2'); MESSAGE('Item last %1', "Sales Price"."Item No."); MESSAGE('Item starting date %1', "Sales Price"."Starting Date"); MESSAGE('Item ending date %1', "Sales Price"."Starting Date"-1); "Sales Price"."Ending Date":="Sales Price"."Starting Date"-1; "Sales Price".MODIFY(TRUE); END; END;
My text file
1010100004 25/10/18 1 14,08 1010100002 26/10/18 1 12,65
where the first column is ITEM_No, the second is the Starting Date, the third is quantity and the last column is the price.
For some reason is not poping the message ("begin2") which means that this condition IF "Sales Price".FINDLAST THEN BEGIN is not being verified.
My table have a few rows and I don't know why he can't get the last record.
All the code of xmlport is here below,
Sales Price - Import::OnBeforeInsertRecord() nRecNum += 1; dlgProgress.UPDATE(3, nRecNum); "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",''); "Sales Price".SETRANGE("Unit of Measure Code",''); //"Sales Price".SETRANGE("Minimum Quantity",QT) DataInicioText:=COPYSTR(DATAINI,1,8); dia := COPYSTR(DataInicioText,1,2); mes := COPYSTR(DataInicioText,4,2); ano:= COPYSTR(DataInicioText,7,4); EVALUATE(DataInicio,dia+mes+ano); "Sales Price".SETRANGE("Starting Date",DataInicio); "Sales Price"."Starting Date":=DataInicio; IF "Sales Price".FINDFIRST THEN BEGIN IF DataInicio < "Sales Price"."Starting Date" THEN "Sales Price".DELETEALL; END; "Sales Price"."User ID":=USERID; "Sales Price"."Data criacao":=TODAY; "Sales Price"."Item No.":=PRODUTO; "Sales Price"."Allow Invoice Disc." :=TRUE; "Sales Price"."VAT Bus. Posting Gr. (Price)":='NAC'; "Sales Price"."Allow Invoice Disc.":=TRUE; "Sales Price"."Sales Code":='ALL'; "Sales Price"."Sales Type":=1; "Sales Price"."Currency Code":=''; "Sales Price"."Variant Code":=''; "Sales Price"."Ending Date":=0D; "Sales Price".VALIDATE("Sales Price"."Sales Code",'ALL'); Item.GET(PRODUTO); "Sales Price"."Unit of Measure Code":=Item."Base Unit of Measure"; //Quantity Quantity:=FORMAT(QT); EVALUATE("Sales Price"."Minimum Quantity",Quantity); //Unit Price Price:=FORMAT(PVP); EVALUATE("Sales Price"."Unit Price",Price); //Unit Price with vat VATPercentageProd:=Item."VAT Prod. Posting Group"; VATPercentageBus:=Item."VAT Bus. Posting Gr. (Price)"; VATPostingSetup.GET(VATPercentageBus,VATPercentageProd); VATPerCent:=VATPostingSetup."VAT %"; EVALUATE(PriceVAT,PVP); "Sales Price"."Unit Price Including VAT":=ConvertPriceToVAT(VATPerCent,PriceVAT); IF NOT "Sales Price".INSERT(TRUE) THEN BEGIN MESSAGE('begin1'); MESSAGE('check %1',"Sales Price".FINDLAST); IF "Sales Price".FINDLAST THEN BEGIN MESSAGE('begin2'); MESSAGE('Item last %1', "Sales Price"."Item No."); MESSAGE('Item starting date %1', "Sales Price"."Starting Date"); MESSAGE('Item ending date %1', "Sales Price"."Starting Date"-1); "Sales Price"."Ending Date":="Sales Price"."Starting Date"-1; "Sales Price".MODIFY(TRUE); END; END;
0
Answers
-
May be if you can make your Question Short and let us know what exactly you unable to achieve?Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/1 -
I have a few rows in sales price table for a specific product ok? So when I upload a textfile using a xmlport I want to fill the last row filled, before the import and with my code I ca'nt find it ( IF "Sales Price".FINDLAST) liek the image.
At the moment i'm filling the last row but the previous before the last is not being filled
0 -
But where I will do that? In the code unit I created? If yes in each event?0
-
LOCAL [EventSubscriber] SalesPriceOnAfterInsert(VAR Rec : Record "Sales Price";RunTrigger : Boolean) IF NOT RunTrigger OR Rec.ISTEMPORARY THEN EXIT; CLEAR(xSalesPrice); xSalesPrice.SETRANGE("Item No.", Rec."Item No."); xSalesPrice.SETRANGE("Sales Type", Rec."Sales Type"); xSalesPrice.SETRANGE("Sales Code", Rec."Sales Code"); xSalesPrice.SETFILTER("Starting Date", '<%1', Rec."Starting Date"); xSalesPrice.SETRANGE("Currency Code", Rec."Currency Code"); xSalesPrice.SETRANGE("Variant Code", Rec."Variant Code"); xSalesPrice.SETRANGE("Unit of Measure Code", Rec."Unit of Measure Code"); xSalesPrice.SETRANGE("Minimum Quantity", Rec."Minimum Quantity"); IF xSalesPrice.FINDLAST THEN BEGIN xSalesPrice.VALIDATE("Ending Date", Rec."Starting Date" - 1); xSalesPrice.MODIFY(TRUE); END;
Follow me on my blog juhl.blog0 -
But I define that piece of code in a codeunit created by me but where I link that event to the subscriber itself in
table Sales Price?0 -
But I don't need to define anything in Sales Price table? In this table I don't have anything in OnInsert() function linked to any event...0
-
With this piece of code it will run ALWAYS when a OnInsert occurs in this table? Sorry but i'm new in navision events world !0
-
Thanks. Just a question. xSalesPrice is a global (record of type Sales Price). Is not necessary to initialized this var? Or say that xSalesPrice:=Rec ?0
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