Multiple DataItems in dataport

jorgitojorgito Member Posts: 115
Dear all,

I am trying to combine many dataports into one.

In the same dataport, I have inserted 3 dataitems. I have a variable of type option that takes 3 values. In the Request Form, I have added 3 radio buttons. The idea is that by clicking a radio button, the data is imported into the appropriate dataitem.

The code in the OnPreDataItem trigger of each DataItem is the following
IF ImportTable <> ImportTable::Item THEN
  CurrDataport.BREAK;

The problem is that when I choose the first radio button (thus the first DataItem), the data is imported correctly. But when I choose one of the other options, no data is imported.

I have the impression that BREAK causes all the trouble. I even tried SKIP but it didn't work.

Any ideas?

Jorgito

Comments

  • kinekine Member Posts: 12,562
    Post the code you are using for skipping the dataitems, please.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • jorgitojorgito Member Posts: 115
    Global variable : ImportTable Option (Item,Cust,Vend)

    3 DataItems : Item, Customer, Vendor
    Item - OnPreDataItem()
    IF ImportTable <> ImportTable::Item THEN
      CurrDataport.BREAK;
    
    Customer - OnPreDataItem()
    IF ImportTable <> ImportTable::Cust THEN
      CurrDataport.BREAK;
    
    Vendor - OnPreDataItem()
    IF ImportTable <> ImportTable::Vend THEN
      CurrDataport.BREAK;
    

    I even tried CurrDataport.SKIP in all three triggers, but did not work...
  • Alex_ChowAlex_Chow Member Posts: 5,063
    Your better off writing a process only report that runs these dataports modally. 8)
  • SavatageSavatage Member Posts: 7,142
    Here's a snipit of code from a dataport that when I import items it fills in the Item Unit Of Measure table too. I don't know if it's helpful
    //60 Character Description field on import automatically split into 2
    Item.Description := COPYSTR(mydescription, 1, 30);
    Item."Description 2" := COPYSTR(mydescription,31,30);
    
    IF "Item Unit Of Measure".GET(Item."No.", Item."Base Unit of Measure") THEN
      VALIDATE(Item."Base Unit of Measure")
    ELSE BEGIN
      "Item Unit Of Measure".Code := Item."Base Unit of Measure";
      "Item Unit Of Measure"."Item No." := Item."No.";
      "Item Unit Of Measure"."Qty. per Unit of Measure" := 1;
      "Item Unit Of Measure".INSERT(TRUE);
      VALIDATE(Item."Base Unit of Measure");
    END;
    

    I guess I should Have read it closer.

    How about 3 functions 1 for each and do each different thing there
    Item - OnPreDataItem()
    IF ImportTable = ImportTable::Item THEN
    functionITEM;

    Customer - OnPreDataItem()
    IF ImportTable = ImportTable::Cust THEN
    functionCUST;

    Vendor - OnPreDataItem()
    IF ImportTable <> ImportTable::Vend THEN
    functionVEND;
  • jversusjjversusj Member Posts: 489
    Savatage wrote:
    Here's a snipit of code from a dataport that when I import items it fills in the Item Unit Of Measure table too. I don't know if it's helpful
    //60 Character Description field on import automatically split into 2
    Item.Description := COPYSTR(mydescription, 1, 30);
    Item."Description 2" := COPYSTR(mydescription,31,30);
    
    IF "Item Unit Of Measure".GET(Item."No.", Item."Base Unit of Measure") THEN
      VALIDATE(Item."Base Unit of Measure")
    ELSE BEGIN
      "Item Unit Of Measure".Code := Item."Base Unit of Measure";
      "Item Unit Of Measure"."Item No." := Item."No.";
      "Item Unit Of Measure"."Qty. per Unit of Measure" := 1;
      "Item Unit Of Measure".INSERT(TRUE);
      VALIDATE(Item."Base Unit of Measure");
    END;
    

    I guess I should Have read it closer.

    How about 3 functions 1 for each and do each different thing there
    Item - OnPreDataItem()
    IF ImportTable = ImportTable::Item THEN
    functionITEM;

    Customer - OnPreDataItem()
    IF ImportTable = ImportTable::Cust THEN
    functionCUST;

    Vendor - OnPreDataItem()
    IF ImportTable <> ImportTable::Vend THEN
    functionVEND;

    I wish i would have thought of using functions! i hate when "obvious" alternatives escape me when I need them, sometimes.

    I had the same problem reported here, where the first import worked but the second, third, etc data items didn't see the import file. I scrapped the idea and did it some other way, but functions may have been the ticket. Thanks, i'll keep that in mind!
    kind of fell into this...
  • jorgitojorgito Member Posts: 115
    Savatage wrote:
    How about 3 functions 1 for each and do each different thing there
    Item - OnPreDataItem()
    IF ImportTable = ImportTable::Item THEN
    functionITEM;

    Customer - OnPreDataItem()
    IF ImportTable = ImportTable::Cust THEN
    functionCUST;

    Vendor - OnPreDataItem()
    IF ImportTable <> ImportTable::Vend THEN
    functionVEND;

    And what should I put inside functionITEM, functionCUST and functionVEND??

    Remember that this is a dataport. The first DataItem will import the data and all the other DataItems will do nothing.
  • SavatageSavatage Member Posts: 7,142
    -edit-

    i think i see your dilemma now - when i get into the office - i'll help you rethink the solution (if there is one)
  • BgestelBgestel Member Posts: 136
    - Make a dataport
    - make 1 data item Integer
    -set autosave , update and replace to no
    - make a global type = text 1024
    - make 1 dataportfield set it to the global
    - import the file and parse the global youreself for each record using the SELECTSTR command

    -i think multiple dataitems will not work because nav wil skip the first records in case you select the second or thirth option
    **********************
    ** SI ** Bert Van Gestel **
    **********************
  • jorgitojorgito Member Posts: 115
    Hi all.

    The original idea was by taking advantage of the dataport's functionality (DataItem, Dataport Fields etc.) to create one dataport that can handle many DataItems. So, instead of creating 5 dataports, I would merge all into 1 dataport and every time select (using radio buttons) which DataItem to import into.

    Most of the solutions in this topic say that I should recreate the dataport's functionality using functions and use these instead. Let me point out that I do not HAVE TO use 1 dataport, I was just curious if I CAN.

    So let me go back to the beginning:

    3 DataItems, 3 radio buttons, a CurrDataport.BREAK in each OnPreDataItem.

    If I select the 1st DataItem, NO BREAK is called and the file is imported correctly. If I select another DataItem, at least one BREAK occurs and the text file is ignored.

    What is wrong with the BREAK function??

    The same happens with SKIP...

    Jorgito
  • BgestelBgestel Member Posts: 136
    you can not import multiple file types in diferent dataitems using standart data port functionality and only 1 dataport, this is because NAV looks for the dataitem seperator .

    This means that dataitem 3 needs to be preceeded by at least 2 dataitem seperators, usealy set to <<newline>>

    that is why it doesnt work. :wink:
    **********************
    ** SI ** Bert Van Gestel **
    **********************
  • Joe_CoolJoe_Cool Member Posts: 7
    Bgestel wrote:
    you can not import multiple file types in diferent dataitems using standart data port functionality and only 1 dataport, this is because NAV looks for the dataitem seperator .

    This means that dataitem 3 needs to be preceeded by at least 2 dataitem seperators, usealy set to <<newline>>

    that is why it doesnt work. :wink:

    Maybe a silly question, but what if you set the DataItemSeparator = <>? could this work then?
    I was interested in the possibility of using the request form to select different file formats that would be imported into the same table. So each dataitem would be set for the different import file layouts.

    Although we are presently importing the two layouts with different dataports, it would be an easier process for the users if it was one import dataport with an option for the different file formats.
Sign In or Register to comment.