dataport

Horse06Horse06 Member Posts: 496
Some questions on dataport import. I create a dataport and import the csv file to a table. The purpose is to import multiple customer's shipping address with the same duplicate sales order no. and so in the csv file I have 7 columns(Order No, Company, Address1, Address2, city, state, zip).
The data is imported, but it only imported one record and I have 11 records in the file. In my coding, I have something like this:
If Shipment.Order No. get(No.) then
Begin
Shipment.Name1 :=Company;
Shipment.Address :=Address1;
and the rest of the mapping fields
End;

My table which the file is imported has line no and could it be this reason which prevent the rest of the records from be imported?
Also I tried to add one column in my file and map the shipment line no with variable lineno, but it still doesn't work. Can any expert have any suggestions? Thanks a lot!!

Comments

  • kinekine Member Posts: 12,562
    Have you something like .INSERT or .MODIFY in your code? Best is to disable the AutoInsert, AutoModify etc. and do it yourselfs.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • WaldoWaldo Member Posts: 3,412
    Indeed.
    Many times, I just use dataport to have the OnAfterImport-triggers, the seperation properties and the file selection. Then I just use an integer element, variables to read the file and the rest in code... . Gives you much more flexibility, maintainability and readability (don't know if these are actual English words though :-k ) ... .

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • Horse06Horse06 Member Posts: 496
    If I add the line no in the dataport field, there is an error and if I take away the line no, when data is imported the number is zero in this fields. I also tried to use insert and modify, but only record is imported. Help, please! Thanks!
  • SavatageSavatage Member Posts: 7,142
    Always a quick & easy test is to first add your line no field to the dataport fields.

    Now take an order or whatever table this is that alreayd has multiple addresses and use your dataport to EXPORT data.

    Then look at the file it created and see if your datafile is setup the same way.

    I'm assuming this is due to quick typing in a post
    If Shipment.Order No. get(No.) then
    If Shipment."Order No.".GET("No.") 8)

    So this table is Shipment and the Key fields are?
  • Horse06Horse06 Member Posts: 496
    Hi, Savatage and thank you! In the post, it is a quick typing, but in my real code in Navision, it is " If Shipment.get(no) then ". no is the variable I declared. The data is imported, but it always imports the last line from the sheet and line no is zero. If I manually changed the line no from zero to 10000, then when I imported it again, it still imported the last line. Please help me! Thanks!
  • SavatageSavatage Member Posts: 7,142
    Sounds like your Line number is not incrementing.
    and it keeps writing the data over the same line over and over again.

    Either in your datafile add the line numbers to the dataline
    10000
    20000
    30000
    40000
    etc..

    or have the dataport do it.
    OnPreDataItem()
    "Line No." := 0;

    OnAfterImportRecord()
    "Line No." := "Line No." + 10000;
  • Horse06Horse06 Member Posts: 496
    Thank, Harry! Still it doesn't work. This is what I did:
    the first way: 1. Add line no column in my file and fill in the numbers
    2. add Line No to the dataport field
    3. here is the coding:


    IF "Multiple Ship-to".GET(OrderNo) THEN
    BEGIN
    "Multiple Ship-to"."Order No.":=OrderNo;
    "Multiple Ship-to"."Ship-to Name" :=name;
    "Multiple Ship-to"."Line No." := lineno;
    "Multiple Ship-to"."Ship-to Name 2" :=contact;
    "Multiple Ship-to"."Ship-to Address" :=address1;
    "Multiple Ship-to"."Ship-to Address 2" :=address2;
    "Multiple Ship-to"."Ship-to City" :=city;
    "Multiple Ship-to"."Ship-to ZIP Code" := zip;
    "Multiple Ship-to"."Ship-to State" :=state;
    "Multiple Ship-to"."Ship-to Country Code" :=country;

    Templine := Templine + 1;
    "Multiple Ship-to".INSERT;
    End;
    When I run the dataport, it pops up an error: "You cannot enter 'lineno' in Integer. The cursor is in front the invalid character.".
    The second way: you recommended adding some coding. This is what I do: Take the lineno numbers from my file and add the coding you recommended. Still it doesn't work.
    I find the problem is if I add the line no to the dataport field, it gives this error. But if I take out Line No from Dataport Field, it imports correctly, but only one record. I really don't know what to do and I spent two days on it. Thank you for your time, Harry! Can you or some other experts have some other suggestions? Thanks!!!!
  • SavatageSavatage Member Posts: 7,142
    perhaps we dont have enuf info here, how is
    IF "Multiple Ship-to".GET(OrderNo) THEN 
    BEGIN
    

    related? This looks strange to me.

    What are the key fields of "Multiple Ship-To."?

    I see you code but where i the incrementing of the line no?

    can you manually add in multiple ship-to's or that does that error out too?
  • SavatageSavatage Member Posts: 7,142
    more observations...
    This is a custom table - what is line no declared as on the table? Not integer?

    "Multiple Ship-to"."Line No." := lineno; will work if you are importing the line no with the data else it would be
    "Multiple Ship-to"."Line No." := "Line No." + 10000;

    if you use table 222 as a guide it uses Cust No & Code as it's keys.
    Each Ship-to has it's own code.
    Now do you want to use the "Order No" as it's code?
    If so Line No is not needed unles it's one of the keys.

    also Why wouldn't you use table 222? what's different about this table?
    The purpose is to import multiple customer's shipping address with the same duplicate sales order no
    & Can you explain this. What do you mean Same Duplicate Sales order No? if your just trying to import 7 fields into a table it should't be too difficult. As long as your key fields are SET & VALIDATED.

    Is this a one tim dataport, if so you can just hard code the dup order number instead of using that GET which I can't believe it works myself
    IF "Multiple Ship-to".GET(OrderNo) THEN 
    BEGIN 
    "Multiple Ship-to"."Order No.":=OrderNo;
    
    :-k
  • Horse06Horse06 Member Posts: 496
    Thank you so much, Harry! Yes, datatype of the Line no in the new talbe is integer. No matter how hard I tried, it didn't work. But how to just hard code the dup order number? Thank you for your time! Is it wrong to add line no to the dataport field? Please !
  • SavatageSavatage Member Posts: 7,142
    The posts above ask a few questions. without them being answered it's hard to say. I don't know
    -the design of the table?
    -what it's keys are (if the only key for example is orderno - it will keep overwriting if you keep using the same orderno) unless you add orderno & line no as a key or orderno & some code field (for example)
    -what you are trying to relate this table to?
    -if you're trying to do something like table 222?
    -what is a dup order no (it this a real # or just something to help you import)
    -can you manually add in two lines in this new table?
    -plus what ever else was asked above.
    -what are you trying to GET with the GET statement?
  • Horse06Horse06 Member Posts: 496
    Thanks, Harry! I am sorry I didn't make it clear. This new table has been used for a while and it is related to sales header, which is one to many relationship. One sales order has multiple shipping locations. It's something like the sales order form of sales header with sales line. Since we have to manually keyed in many addresses when we have multiple drop shipment, we decide to import the data to this table.
    1. The key for this tableis Order No + Line No
    2. It is related to Sales Header
    3. The order nos in the csv file which I am going to import are real order numbers. I first got the order no from the header of the sales order form and then based on the order no, I tested typing 6 records with the same sales order no.
    Normally it's very easy to import the data to the tables, but not this time. Thanks for your time!
  • Horse06Horse06 Member Posts: 496
    O:) Thanks, Harry! I have solved it.
Sign In or Register to comment.