problem in dataport

vikasvikas Member Posts: 46
edited 2004-05-14 in Navision Attain
Hi,

I have a query regarding dataport.
I have a text(csv) file which looks like this

No,Name,Address
Item No,Quantity,Price

Now i want to push 1st line to the customer table & 2nd line to the item table.

Please help me in this regard.

Thanks,
Vikas S. Shettar

Comments

  • WiechardtWiechardt Member Posts: 25
    I take it the second line is information on the selling price of an Item for the imported customer?

    If that is the case, I would do the following:

    Declare 7 Variables in your Dataport:
    gvImportField1 Text
    gvImportField2 Text
    gvImportField3 Text
    gvImportLineCounter Integer
    gvCustomer Record Customer
    gvSalesPrice Record Sales Price
    gvImportCustNo Text

    Declare your Dataport "DataItem" to be either Customer or Item, but modify the DataItem properties to:
    AutoUpdate: False
    AutoInsert: False
    AutoReplace: False

    Assign these 3 fields as your DataPortFields. What will happen is, when importing, gvImportField1 will then either contain a Customer No OR Item No.

    Now, in the OnAfterImportRecord trigger of your DataItem, you must do the following:

    IF gvImportCounter = 1 THEN BEGIN
    gvImportedCustNo := ImportField1;
    IF NOT gvCustomer.GET(gvImportField1) THEN BEGIN //Insert Customer
    gvCustomer.INIT;
    gvCustomer."No." := COPYSTR(gvImportField1, 1, 20);
    gvCustomer.VALIDATE(Name, COPYSTR(gvImportField2, 1, 30));
    gvCustomer.Address := gvImportField3;
    gvCustomer.INSERT;
    END;
    gvImportCounter += 1;
    END
    ELSE IF gvImportCounter = 2 THEN BEGIN
    gvSalesPrice.RESET;
    gvSalesPrice.SETRANGE(gvSalesPrice."Sales Type"::Customer);
    gvSalesPrice.SETRANGE(gvSalesPrice."Sales Code", gvImportCustNo);
    gvSalesPrice.SETRANGE(gvSalesPrice."Item No.", gvImportField1);

    IF NOT gvSalesPrice.FIND('-') THEN BEGIN //Insert Sales Price
    gvSalesPrice.INIT;
    gvSalesPrice."Item No." := COPYSTR(ImportField1, 1, 20);
    gvSalesPrice."Sales Type" := gvSalesPrice."Sales Type"::Customer;
    gvSalesPrice."Sales Code" := gvImportCustNo;
    gvSalesPrice.INSERT;
    END;
    gvImportCounter := 1;
    END;
  • vikasvikas Member Posts: 46
    but sir,
    i have to insert records simaltanously into two tables. 1st line into customer table and 2nd line into item table.
    can u tell me how??
    because i am a fresher....
  • FPulsfortFPulsfort Member Posts: 43
    The Code above works fine when you replace the part "gcSalesPrice" with "Item", where you insert the Data in the Itemtable! You know, how to do this?

    What do you mean with simultaniously? You can only read one line of the file per step! And with the counter you decide if you have to insert a customer or a item.

    Greetings,
    Frank
  • vikasvikas Member Posts: 46
    sir...
    but it is not entering into the first loop itself.
  • Tommy_SchouTommy_Schou Member Posts: 117
    edited 2004-05-14
    Define some global variables that contain the fields in the file you are reading. Use the table (virtual table "Number" should be used off cause :)*edited*)Standardtext as your dataitem. In the properties set autosave and autoupdate to NO. Use the global variables as dataport fields. Now on the OnAfterImportRecord you will make the code that updates the Customer AND the Item table with the data that you have read into the global variables.
    Best regards
    Tommy
  • WiechardtWiechardt Member Posts: 25
    Sorry vikas, I forgot something in the code...

    In the PreDataItem code, you must enter another line of code...

    gvImportCounter := 1;

    This will ensure that the first section of code is executed...

    Without this line of code, the Dataport will start to run without a value in the gvImportCounter variable - thus not executing the first section of code.
Sign In or Register to comment.