Dataport SKIP

tazzy30
Member Posts: 52
Hello,
I have created a dataport which imports Purchase Invoices, the dataport works fine if the CSV file has only header details, but as soon as lines are added, it doesn't work.
It appears the CurrDataport.SKIP in the header dataitem is not triggered.
Does anyone have any idea what this could be?
Thank You
I have created a dataport which imports Purchase Invoices, the dataport works fine if the CSV file has only header details, but as soon as lines are added, it doesn't work.
It appears the CurrDataport.SKIP in the header dataitem is not triggered.
IF PurchaserCode <>'' THEN BEGIN PurchHead."Buy-from Vendor No." := PurchaserCode; IF NOT Vend.GET(PurchHead."Buy-from Vendor No.") THEN BEGIN Vend.INIT; Vend."No." := PurchHead."Buy-from Vendor No."; Vend.INSERT; END; PurchHead.VALIDATE("Buy-from Vendor No.",PurchaserCode); PurchHead.VALIDATE("Shortcut Dimension 1 Code",Dept); PurchHead.VALIDATE("Shortcut Dimension 2 Code",SBC); PurchHead."Your Reference" := Notes; PurchHead.MODIFY; CurrDataport.SKIP; END ELSE ERROR('Employee has not been specified.');
Does anyone have any idea what this could be?
Thank You
0
Comments
-
First, i indented your code properly, check if it's what you want
IF PurchaserCode <>'' THEN BEGIN PurchHead."Buy-from Vendor No." := PurchaserCode; IF NOT Vend.GET(PurchHead."Buy-from Vendor No.") THEN BEGIN Vend.INIT; Vend."No." := PurchHead."Buy-from Vendor No."; Vend.INSERT; END; PurchHead.VALIDATE("Buy-from Vendor No.",PurchaserCode); PurchHead.VALIDATE("Shortcut Dimension 1 Code",Dept); PurchHead.VALIDATE("Shortcut Dimension 2 Code",SBC); PurchHead."Your Reference" := Notes; PurchHead.MODIFY; CurrDataport.SKIP; END ELSE ERROR('Employee has not been specified.');
then, why do you want to skip a line after you've done modifications?what do you think you'll skip?0 -
Thank You for your reply, If i dont put a Skip then it reads the next line in the CSV file as a header as supposed to a line (second dataitem)0
-
currdataport.skip does not skip a line in the file, but a record in NAV (useless in your situation).
maybe you can post your dataport and/or a sample of csv file?
anyway, i think that for complex importations, it's better to use a report and FILE functions0 -
Thank you for your reply i would attach the items on here but i cant see the option to do so0
-
Thank You, this is CSV
40000,ADM,MERCEDES,Testing,Test Proj (Purchase Header)
(Empty Line)
5410,Mileage,115,0.4,GBP,,1,,5,46 (Purchase Lines)
This is the dataportOBJECT Dataport 50001 Purchase Invoice Import { OBJECT-PROPERTIES { Date=19/03/09; Time=12:04:47; Modified=Yes; Version List=; } PROPERTIES { } DATAITEMS { { PROPERTIES { DataItemTable=Table2000000026; DataItemVarName=PurchaseHeader; AutoSave=No; DataItemTableView=SORTING(Number); OnPreDataItem=BEGIN PurchHead."Document Type" := PurchHead."Document Type"::Invoice; END; OnAfterImportRecord=BEGIN IF PurchaserCode <>'' THEN BEGIN PurchHead."Buy-from Vendor No." := PurchaserCode; IF NOT Vend.GET(PurchHead."Buy-from Vendor No.") THEN BEGIN Vend.INIT; Vend."No." := PurchHead."Buy-from Vendor No."; Vend.INSERT; END; PurchHead.VALIDATE("Buy-from Vendor No.",PurchaserCode); PurchHead.VALIDATE("Shortcut Dimension 1 Code",Dept); PurchHead.VALIDATE("Shortcut Dimension 2 Code",SBC); IF ProjectCode <>'' THEN DocDim.INIT; DocDim."Table ID" := 38; DocDim."Document Type" := DocDim."Document Type"::Invoice; DocDim."Document No." := PurchHead."No."; DocDim."Dimension Code" := 'PROJECT'; DocDim."Dimension Value Code" := ProjectCode; DocDim.VALIDATE("Dimension Value Code", ProjectCode); PurchHead."Your Reference" := Notes; PurchHead.MODIFY; CurrDataport.SKIP; {END ELSE ERROR('Employee has not been specified.');} END; END; } FIELDS { { ; ;PurchaserCode } { ; ;Dept } { ; ;SBC } { ; ;Notes } { ; ;Project } } } { PROPERTIES { DataItemTable=Table2000000026; DataItemVarName=PurchaseLine; AutoSave=No; DataItemTableView=SORTING(Number); OnPreDataItem=BEGIN PurchLine."Document Type" := PurchLine."Document Type"::Invoice; LineNo := 10000; END; OnBeforeImportRecord=BEGIN CLEAR(PurchLine) END; OnAfterImportRecord=BEGIN IF (AccountCode = '') AND (Desc = '') THEN CurrDataport.SKIP; GLAcc := COPYSTR(AccountCode,1,4); PurchLine."Document No." := PurchHead."No."; PurchLine."Line No." := LineNo; LineNo += 10000; PurchLine."Buy-from Vendor No." := PurchHead."Buy-from Vendor No."; IF TotalAmount = 0 THEN BEGIN IF NOT INSERT THEN MODIFY; CurrDataport.SKIP; END; TempLine := PurchLine; PurchLine.VALIDATE(Type,PurchLine.Type::"G/L Account"); PurchLine.VALIDATE("No.",GLAcc); PurchLine.Description := Desc; PurchLine.VALIDATE("Shortcut Dimension 1 Code",TempLine."Shortcut Dimension 1 Code"); PurchLine.VALIDATE("Shortcut Dimension 2 Code",TempLine."Shortcut Dimension 2 Code"); PurchLine.VALIDATE("VAT Prod. Posting Group", VATProdPostGrp); IF Miles <> 0 THEN BEGIN PurchLine.VALIDATE(Quantity,Miles); PurchLine.VALIDATE("Direct Unit Cost",UnitCost); END ELSE BEGIN PurchLine.VALIDATE(Quantity,1); PurchLine.VALIDATE("Direct Unit Cost",TotalAmount); END; IF NOT INSERT THEN MODIFY; END; } FIELDS { { ; ;AccountCode } { ; ;Desc } { ; ;Miles } { ; ;UnitCost } { ; ;PurchLine."Currency Code" } { ; ;LocalCurrAmt } { ; ;ExchangeRate } { ; ;PurchLine."Direct Unit Cost" } { ; ;VATProdPostGrp } { ; ;TotalAmount } } } } REQUESTFORM { PROPERTIES { Width=9020; Height=3410; } CONTROLS { } } CODE { VAR PurchaserCode@1040000 : Code[10]; Dept@1040001 : Code[10]; SBC@1040002 : Code[10]; Notes@1040003 : Text[30]; Project@1040004 : Code[10]; PurchHead@1040005 : Record 38; PurchLine@1040006 : Record 39; Vend@1040007 : Record 23; ProjectCode@1040008 : Code[20]; DocDim@1040009 : Record 357; LineNo@1040010 : Integer; VATProdPostGrp@1040011 : Code[10]; TotalAmount@1040012 : Decimal; Desc@1040013 : Text[250]; ExpItemNo@1040016 : Integer; Date@1040017 : Date; LocalCurrAmt@1040018 : Decimal; ExchangeRate@1040019 : Decimal; AccountCode@1040014 : Text[50]; GLAcc@1040015 : Code[20]; UnitCost@1040020 : Decimal; Miles@1040021 : Decimal; TempLine@1040022 : Record 39; PROCEDURE SetDocNo@1040000(BlankOrder@1040000 : Record 38); BEGIN PurchHead := BlankOrder END; BEGIN END. } }
0 -
the problem is that you don't have a csv suitable for dataports, because you have
header
-
line
line
line
--
header
-
line
--
header
-
line
in this way it's difficult to figure out what dataitem you must fill in. for this reason, i suggest you to use a report or codeunit in order to manage the file as you want. (read the first line of the file, detect if it is an header or a line, insert the record in the appropriate table, go to the next line)
If you have the possibility to change the csv to import, you should create something like:
header
header
header
header
...
lastheader
[carriage return x 2]
line
line
line
...
last line
with this layout of the file, you can set the dataitemseparator property, then insert all the headers, and then all the lines0 -
Thank You for your reply, i should have stated that the csv file will only ever hold one Header and multiple lines, so would this still be the case?0
-
ok, then you have a csv file for each invoice...perferct, you just create a dataport with:
-purchase header (put your business logic for header in this dataitem)
-purchase lines (put your business logic for lines here)
set dataitemseparator properly (i think that the standard "<<NewLine><NewLine>>" fits for you) leave to nav the rest...0 -
just imported your dataport...why did you use 2 integer dataitems instead of purchase header & line?
if you want to insert/modify data manually by code, just set "auto" insert, modify, rename properties of the dataport to NO and then manage your code.0 -
I have also done this however had no luck, it just doesn't want to work0
-
Ok thank you for taking the time out to look0
-
I'm still having the same problem does anyone have any idea's what this could be?0
-
Start Again if your data always & only has
header data
(space)
line data
line data
line data
then your dataport will have both dataitems
Purchase Header
Purchase Line (not linked in anyway!)
Fileformat - Variable
Record Seperator <<NewLine>>
DataItemSeperator <<Newline><NewLine>>
I would create variables for the data you are importing.
Put the var's for the header in the purchase header Dataport fields.
put the var's for the lines in the purchase line dataport fields.
Onafterimportrecord for purchase header add your code to match your var's to their proper nav field validate where necessary. (going to need at least "Document type" & "No.")
Onafterimportrecord for purchase lines add your code to match your var's to their proper nav field validate where necessary. (going to need at least "Document Type", "Document no." & "Line no."0 -
Thank You for your reply Savatage, i have tried this but still no luck, I have inserted a MESSAGE and it seems to be reading everything correctly however the error at the end of the code still appears.
IF "Buy-from Vendor No." <> '' THEN BEGIN IF NOT Vend.GET("Buy-from Vendor No.") THEN BEGIN Vend.INIT; Vend."No." := "Buy-from Vendor No."; Vend.INSERT; END; PurchaseHeader.VALIDATE("Buy-from Vendor No.","Buy-from Vendor No."); PurchaseHeader.VALIDATE("Shortcut Dimension 1 Code",Dept); PurchaseHeader.VALIDATE("Shortcut Dimension 2 Code",SBC); IF ProjectCode <>'' THEN BEGIN DocDim.INIT; DocDim."Table ID" := 38; DocDim."Document Type" := DocDim."Document Type"::Invoice; DocDim."Document No." := "No."; DocDim."Dimension Code" := 'PROJECT'; DocDim."Dimension Value Code" := ProjectCode; DocDim.INSERT; END; DocDim.VALIDATE("Dimension Value Code", ProjectCode); PurchaseHeader."Your Reference" := Notes; PurchaseHeader.MODIFY; CurrDataport.SKIP; END ELSE ERROR('Employee has not been specified.');
0 -
1st...What error?
2nd..Where are you defining a Purchase header? w/code?
3rd..try just importing a purchase order first before adding all the bells n whistles like skipping & inserting vendor's n stuff.
that can all come later.
Here's a post that I put the simplest of simple dataports.
It's for Sales Order - but easily changed to purchase orders.
You can use it as a guide to get your dataport at least importing. once you get that working then add Inserting new vendors & skipping etc.
viewtopic.php?t=160240 -
Hi Tazzy
I just had the exact issue with a similar dataport
You need to use CurrDataport.BREAK not CurrDataport.SKIP to go onto the next dataitem, Skip will only go onto the next record, Break will skip the current dataitem onto the next.
Hope that helps 'Tazzy'!!0 -
bgadhvi1 wrote:Hope that helps 'Tazzy'!!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