Import to Two Tables

the_boy_wonderthe_boy_wonder Member Posts: 8
We need to import a CSV file into two tables.

The CSV file is auto-generated by another system and is a single row per record. Half of the row data will go to Table1, the other half to Table2.

My current Dataport is build using Table1 but I'm unsure how to code the other fields to go to Table2. THe Primary Key of the record is in both Table1 and Table2.

Any ideas?

Thanks

Comments

  • FLPFLP Member Posts: 9
    Introduce table2 as a Global Var and make code in 'OnAfterImportRecord' on the table1 dataitem.
    Finn Landgreen-P
    www.corpital.com
  • the_boy_wonderthe_boy_wonder Member Posts: 8
    Thanks. Are you able to advise of the code required?
  • garakgarak Member Posts: 3,263
    u can also do following (example)

    U CSV file hast, lets say 10 fields. Field 1-5 for Table A Field 6-10 and 1 for Table B. All fieldclasses are in this csv (like decimal, code, etc.)

    1. create a new Dataport based on DateItem INTEGER.
    2. disable the "Auto" Options
    3. set the Delimiter and the Separator
    4. set the FileFormat
    5. add your needed Datatype variables as array (for example DecimalArray, IntegerArray, Codearray)
    6. set these Arrayvaiables as SourceExpr. in the field Designer (like first DecArray[1], CodeArray[1], DecArray[2], and so on <- based on your csv structure) <- also you can use only a Text Arry but must then convert the values with evaluate if, for example an interger is needed.
    7. clear in on before Import the Arrays
    8. create 2 Variebals for Table A and Table B
    9. in on AfterImport Trigger of Dataitem Integer you fill Table A and Table B based on your Array fields.

    Instead of only using the Array variables, you can also use as Dataitem Table A and for the rest fields u use the Variables and fill then the Table B in OnAfterImport Trigger.

    regards
    Do you make it right, it works too!
  • FLPFLP Member Posts: 9
    A quick example using some of the things posted by garak.
    Finn Landgreen-P
    www.corpital.com
  • HanenHanen Member Posts: 281
    Hi,

    Can I do the same in the export?????
    It means can I export to a txt or a csv file from two tables????? :cry:



    Thanks for help!!!!!
    Regards

    Hanen TALBI
  • rhpntrhpnt Member Posts: 688
    We need to import a CSV file into two tables.

    The CSV file is auto-generated by another system and is a single row per record. Half of the row data will go to Table1, the other half to Table2.

    My current Dataport is build using Table1 but I'm unsure how to code the other fields to go to Table2. THe Primary Key of the record is in both Table1 and Table2.

    Any ideas?

    Thanks

    Split the data into separate .txt files and import them according to NAV standards. You'll get a clear solution and more control over import transactions.
  • HanenHanen Member Posts: 281
    NO, the purpose is to have in the same text file a line for the header and then lines for details.....
    Example:
    Sales Header
    Sales Lines 1
    Sales Lines 2
    Sales Lines 3
    Sales Lines 4
    Regards

    Hanen TALBI
  • rhpntrhpnt Member Posts: 688
    Hanen wrote:
    NO, the purpose is to have in the same text file a line for the header and then lines for details.....
    Example:
    Sales Header
    Sales Lines 1
    Sales Lines 2
    Sales Lines 3
    Sales Lines 4

    Good luck then...
  • SavatageSavatage Member Posts: 7,142
    we use two tables - not linked but our data is like this

    header1
    header2
    header3
    header4
    <space>
    lines for 1
    lines for 2
    lines for 3
    lines for 4

    there's lots of post about importing sales header & lines - search the forum - you'll probably get a few good examples.
Sign In or Register to comment.