OnAfterImportRecord trigger firing twice for ea line in file

CobaltSS
Member Posts: 137
Hi,
I'm running a dataport from a form. The data is all imported correctly, but the data written is doubled. For example, there are four lines in the import file, and I'm get 8 lines (two of each) when the file is written. I'm reading into an Integer data item, and using Global variables to store the incoming data, which then uses code in the OnAfterImportRecord trigger to store the data in the table. When I watch the import via the debugger, the OnAfterImportRecord trigger executes twice for each line in the import file.
I've never seen anything like this before. Any advice greatly appreciated.
cheers,
I'm running a dataport from a form. The data is all imported correctly, but the data written is doubled. For example, there are four lines in the import file, and I'm get 8 lines (two of each) when the file is written. I'm reading into an Integer data item, and using Global variables to store the incoming data, which then uses code in the OnAfterImportRecord trigger to store the data in the table. When I watch the import via the debugger, the OnAfterImportRecord trigger executes twice for each line in the import file.
I've never seen anything like this before. Any advice greatly appreciated.
cheers,
0
Answers
-
What's the point of using the integer dataitem?
You can import into variables on the regular table dataitem.0 -
Hi Savatage,
Yes I know. But I'd rather not. And that still doesn't tell me why the trigger is firing two times for each line read. If you think it's related to reading the data into a text variable instead of the directly into the table, then I'll change the 'port, but I've never experienced this problem before. I don't write a lot of dataports, but I've never had a problem with this approach.
cheers,0 -
I'm sure it's something simple but without seeing the dataport it's hard to nail down.
I would use the one dataitem for the actual table you want to import to.
Create your variables (as you did) to import the data.
Enter these variables into the "Dataport Fields"
OnAfterImportRecord() map the fields to their proper NAv field
Item.validate("No.",varItemNo);
Item.Description := varDescription;
etc etc0 -
I would check for non-ascii characters on your text file.Confessions of a Dynamics NAV Consultant = my blog
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book0 -
Hi Harry,
That's exactly the approach I took. The data from each line goes into two tables (like a Sales Header and Sales Line), which is the other reason I used then Integer dataitem and then I validate the Dataport Fields into the tables as appropriate.
I could send you the dataport and txt file if you'd like....
cheers,0 -
can you give a small sample of what the data file looks like?
Does each line have some type of marker - telling us if it's a line or a header?
we import sales orders too.. our data is like this
header 1
header 2
header 3
<space>
line 1 for header 1
line 1 for header 2
line 1 for header 3
see if this adds some light..
viewtopic.php?t=160240 -
This is a direct cut and paste:
************
BTE 0332844 PHILIP HARRISON 20100611 VR5 CP MPL 2 N
BTE 0332844 PHILIP HARRISON 20100611 160-02-350-00 1 N
BTE 0332844 PHILIP HARRISON 20100611 /C 0 N
BTE 0332844 PHILIP HARRISON 20100611 /C45 0 N
************
The file is TAB separated. Columns are ITem Type, External Doc No., End User Name, Order Date, Item No., Qty, Order Type, and Serial No. (not shown in this import file)
cheers,0 -
CobaltSS wrote:This is a direct cut and paste:
************
BTE 0332844 PHILIP HARRISON 20100611 VR5 CP MPL 2 N
BTE 0332844 PHILIP HARRISON 20100611 160-02-350-00 1 N
BTE 0332844 PHILIP HARRISON 20100611 /C 0 N
BTE 0332844 PHILIP HARRISON 20100611 /C45 0 N
************
The file is TAB separated. Columns are ITem Type, External Doc No., End User Name, Order Date, Item No., Qty, Order Type, and Serial No. (not shown in this import file)
cheers,
this data is familiar to you not us , so it appears you need to generate some of your own data IE. line no, cust #, doc type, item item, etc..
so /C45 IS AN ITEM #? what's the point of it having a Qty or Zero?
do you have some custom fields? item type = BTE?
standard choices are ,Account (G/L),Item,Resource,Fixed Asset,Charge (Item)
are you setting the type on the dataport? salesline.type := 'Item';0 -
Hi,
You were correct to have me inspect the Import file. A mysterious extra tab at the end of each line that wasn't accounted for in the Dataport fields seemed to cause the problem. It's all good now.
Thanks so much for your time.
cheers,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