Dataport question...

kirkostaskirkostas Member Posts: 127
Hi,

I want to import three fixed length Ascii files into three tables Vendor, Customer and Item. Can I have one dataport with a custom request form to achieve this?

Is it possible?
kirkostas

Comments

  • Yaroslav_GaponovYaroslav_Gaponov Member Posts: 158
    kirkostas wrote:
    Hi,

    I want to import three fixed length Ascii files into three tables Vendor, Customer and Item. Can I have one dataport with a custom request form to achieve this?

    Is it possible?

    Why not?

    Dataport can export/import more than one table. Need just add to options form case and export/import in compliance with it.
  • kirkostaskirkostas Member Posts: 127
    So can I have three different tables in data item and select at the same time three different fixed length ascii files and each one import a specific table?
    kirkostas
  • nunomaianunomaia Member Posts: 1,153
    You have 3 dataitems in same file.

    Each data item can have its own format, but you can mix lines in dataitems.

    You can import data to a temporary table and modify/Insert data to correct tables.
    Nuno Maia

    Freelance Dynamics AX
    Blog : http://axnmaia.wordpress.com/
  • matttraxmatttrax Member Posts: 2,309
    I think what he means is "Can I have a dataport that imports three separate files all at the same time."

    The answer in that case is no. If you combine them into one file then you can easily import into multiple tables at once, but not as separate files.
  • DenSterDenSter Member Posts: 8,305
    Basically it is one file format per dataport. You can create a dataport that imports/exports into/from multiple tables, but those records would have to be in one file.
  • NaviDevNaviDev Member Posts: 365
    You can create it via codes.

    Ex.
    CLEAR(dataportname);
    dataportname.IMPORT := TRUE;
    dataportname.Filename := toImportFilename1;
    dataportname.RUN;
    
    CLEAR(dataportname);
    dataportname.IMPORT := TRUE;
    dataportname.Filename := toImportFilename2;
    dataportname.RUN;
    
    CLEAR(dataportname);
    dataportname.IMPORT := TRUE;
    dataportname.Filename := toImportFilename3;
    dataportname.RUN;
    
    

    Did not test it but if there is an error with commiting. You can add it :D
    Navision noob....
  • AsallaiAsallai Member Posts: 141
    Or you can set in the Field Designer only One variable with length. After this the variable get the actual line and then you can do anything with this.
    ...you declare 3 record type of variable for the tables and in the OnAfterImportRecord trigger you can use the data and drop between the tables. (COPYSTR...) :-s
  • kirkostaskirkostas Member Posts: 127
    This is very clever Asallai but don't forget that I want to import three different files simultaneously. Or to have a flag, an option box, that it will skip the other tables. For example, I have three tables in my data item (customer, item, vendor) I have a custom request form with an option box and I choose to import my file into Vendor table. I do the following checks:
    Vendor - OnPreDataItem()
    IF NOT (DataItem = DataItem::Vendor) THEN CurrDataport.SKIP;
    
    Vendor - OnBeforeImportRecord()
    IF NOT (DataItem = DataItem::Vendor) THEN CurrDataport.SKIP;
    
    Vendor - OnAfterImportRecord()
    IF DataItem = DataItem::Vendor THEN BEGIN
      // some custom code here...
    END;
    

    But it always try to import my file to customer table and it crashes because length do not match. If I remove customer and item table it works. So how can I bypass the first two tables and import my file only to the third?

    Conclusion is to have one dataport with many data items (many tables) and with a custom request form to import or export data only from the chosen table.
    kirkostas
  • Yaroslav_GaponovYaroslav_Gaponov Member Posts: 158
    Hi

    You can just write empty line to file instead of other data of the table
  • DenSterDenSter Member Posts: 8,305
    kirkostas wrote:
    I want to import three different files simultaneously
    Like I said before, it's one file format per dataport. If you have three different files, you have to have three different dataports or program your own file read codeunit.
  • jlandeenjlandeen Member Posts: 524
    I think you're going to have to compromise on something to get this to work. One question I would have is how much time & energy do you want to spend to make the masterfile import process really elaborate. If it's only run once or twice by a few accounting people is it not better to spend developer/analyst resources on other tasks on the project/implementation?

    As I see it there are 3 solutions:

    1) combine all of your data into 1 big file with 2 line breaks between each dataset (this is the standard DataItemSeperator dataport property). This would allow you to run the import with a pretty straight forward dataport that has 3 data items.

    2) build 3 different dataports that take a different file type. Then have a custom built form or process that gets the filenames from user or somewhere else and then calls the appropriate dataports.

    3) just build 3 different dataports run them manually for each seperate file (not what you want - but it's quick to build and simple).

    I'm sure there are other solutions out there that would work but how much time and energy is smart to spend on building these types of dataports - in my experience these are run once or a few times at Go Live and that's it.
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
  • DenSterDenSter Member Posts: 8,305
    Very well put, and I agree 100% :mrgreen:

    Just for completeness' sake, solution 4: program a codeunit to read the data one line at a time, and decide per line what to do.
Sign In or Register to comment.