Options

OnAfterImportRecord trigger firing twice for ea line in file

CobaltSSCobaltSS 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,

Answers

  • Options
    SavatageSavatage Member Posts: 7,142
    What's the point of using the integer dataitem?

    You can import into variables on the regular table dataitem.
  • Options
    CobaltSSCobaltSS Member Posts: 137
    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,
  • Options
    SavatageSavatage Member Posts: 7,142
    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 etc
  • Options
    Alex_ChowAlex_Chow Member Posts: 5,063
  • Options
    CobaltSSCobaltSS Member Posts: 137
    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,
  • Options
    SavatageSavatage Member Posts: 7,142
    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=16024
  • Options
    CobaltSSCobaltSS Member Posts: 137
    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,
  • Options
    SavatageSavatage Member Posts: 7,142
    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';
  • Options
    CobaltSSCobaltSS Member Posts: 137
    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,
Sign In or Register to comment.