Import txt file and autonumber

ROBOROBO Member Posts: 39
edited 2006-08-14 in Navision Attain
I want to import txt files with a dataport and then use autonumber. But the problem is when I use autoincrement in my table and there are more lines in the text file the line are overwritten. Can someone help me?

ThanX

Comments

  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    What kind of table are you populating?

    I think you will either need to write some code or add the number to your importfile.
  • SavatageSavatage Member Posts: 7,142
    Yes more info Needed...

    But you can do

    OnPreDataItem()
    "Line No." := 1;
    OnAfterImportRecord()
    "Line No." := "Line No." + 1;

    :?: :?: :?:
  • ROBOROBO Member Posts: 39
    ROBO wrote:
    I want to import txt files with a dataport and then use autonumber. But the problem is when I use autoincrement in my table and there are more lines in the text file the line are overwritten. Can someone help me?

    ThanX

    The autonumber field is integer with autoincrement. In the dataport i wrote some code:

    IF msgInfo.FIND('+') THEN
    msgInfo."Nr." := msgInfo."Nr." + 1
    ELSE
    msgInfo."Nr." := 1;
    INSERT(TRUE);
  • SavatageSavatage Member Posts: 7,142
    ="ROBO
    The autonumber field is integer with autoincrement. In the dataport i wrote some code:

    IF msgInfo.FIND('+') THEN
    msgInfo."Nr." := msgInfo."Nr." + 1
    ELSE
    msgInfo."Nr." := 1;
    INSERT(TRUE);

    1) What trigger are you using.
    2) Everytime it hits "ELSE" the number is "1" overwriting the previous "1" are you sure it's finding anything?
    3) What table are you trying to bring this into?
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Please remove the autoincrement. This is not a realy relicable function. We've had some problems with this in the past.
  • ROBOROBO Member Posts: 39
    Please remove the autoincrement. This is not a realy relicable function. We've had some problems with this in the past.
    If I remove autoincrement then automunber doesn't work
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Navision invented no. series for this. Please use either this or use code like in the other navision entry tables.
  • ROBOROBO Member Posts: 39
    Savatage wrote:
    ="ROBO
    The autonumber field is integer with autoincrement. In the dataport i wrote some code:

    IF msgInfo.FIND('+') THEN
    msgInfo."Nr." := msgInfo."Nr." + 1
    ELSE
    msgInfo."Nr." := 1;
    INSERT(TRUE);

    1) What trigger are you using.
    2) Everytime it hits "ELSE" the number is "1" overwriting the previous "1" are you sure it's finding anything?
    3) What table are you trying to bring this into?


    1) it's a dataport that must import text files (single line and multiline). After the import it delete the file.
    2) I want to find the last number that is used
    3) It is a self made table with "nr." as key (integer) this is the field i want the autonumber apply's to.

    Thanx for your help
  • krikikriki Member, Moderator Posts: 9,115
    Please remove the autoincrement. This is not a realy relicable function. We've had some problems with this in the past.
    Strange, because standard Navision uses this in T405:"Change Log Entry" field 1:"Entry No.".
    But the field is a BigInteger, and not an integer.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • krikikriki Member, Moderator Posts: 9,115
    ROBO wrote:
    2) I want to find the last number that is used
    3) It is a self made table with "nr." as key (integer) this is the field i want the autonumber apply's to.

    Use this system:
    Dataport - OnPreDataport():
    msgInfo.RESET;
    IF msgInfo.FIND('+') THEN
      intLastUsedNo := msgInfo."Nr.";
    

    OnAfterImportRecord();
    intLastUsedNo += 1;
    

    Like this, you do the read for the last one only once.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    We've had some strange SQL error that was caused by the autoincrement property. I don't remember precisely what the error was.
  • ROBOROBO Member Posts: 39
    Hi Alain,

    It imports the txt file but the line's get overwritten when its a multiline txt file. Do you have a solution for that also?

    Thanx a lot
  • krikikriki Member, Moderator Posts: 9,115
    We've had some strange SQL error that was caused by the autoincrement property. I don't remember precisely what the error was.
    Maybe it was with an Integer and not a BigInteger?
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • krikikriki Member, Moderator Posts: 9,115
    ROBO wrote:
    Hi Alain,

    It imports the txt file but the line's get overwritten when its a multiline txt file. Do you have a solution for that also?

    Thanx a lot
    In case you do the INSERTS yourself, when you start to fill (in general just after INIT or CLEAR of the record) a new record to be written, put the code I gave you.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • DenSterDenSter Member Posts: 8,307
    I think your dataport is mixing up the variables, or it's not setting the number in the right trigger. To take the whole thing into your own hands, you can import your text file into variables instead of the fields of your table directly, and then write the code to insert the records using the values of the variables.
  • ROBOROBO Member Posts: 39
    I don't insert it myself i use the dataport fields is it possible with this also?
  • ROBOROBO Member Posts: 39
    DenSter wrote:
    I think your dataport is mixing up the variables, or it's not setting the number in the right trigger. To take the whole thing into your own hands, you can import your text file into variables instead of the fields of your table directly, and then write the code to insert the records using the values of the variables.

    I never did this is there an example for this?
  • DenSterDenSter Member Posts: 8,307
    where you enter fields into the dataport fields editor, you can also enter variable names. Then in the OnAfterImportRecord trigger you handle the values.
  • SavatageSavatage Member Posts: 7,142
    ROBO wrote:
    DenSter wrote:
    I think your dataport is mixing up the variables, or it's not setting the number in the right trigger. To take the whole thing into your own hands, you can import your text file into variables instead of the fields of your table directly, and then write the code to insert the records using the values of the variables.

    I never did this is there an example for this?

    This is what I did on post: (As an example)
    http://www.mibuso.com/forum/viewtopic.php?t=9631

    I set it before anything happens & bring it back later
    OnAfterImportRecord()Code:
    Internet_Cust_Orig_Item := "No.";

    Item.GET("Sales Line"."No.");

    IF Item.Blocked THEN
    BEGIN
    "Sales Line"."No." := '99904';
    END;

    "Sales Line".VALIDATE("No.");
    "Sales Line"."Qty. Ordered" := Internet_Cust_Qty;
    "Sales Line".Quantity := Internet_Cust_Qty;
    "Sales Line".VALIDATE("Qty. Ordered");
    "Sales Line"."EDI Unit Price" := Internet_Price;

    "Sales Line"."EDI Item Cross Ref." := Internet_Cust_Orig_Item;

    Importing the data into vaiables & then assigning them to it's proper Navision Field OnAfterImportRecord, as Denster stated, always solves my dataport problems :wink:
  • ROBOROBO Member Posts: 39
    Denster & Savatage and everybody Thanx for your help. The variabele does the trick.

    ThanX again
  • DenSterDenSter Member Posts: 8,307
    Cool, glad you got it to work.

    Veel plezier ermee :mrgreen:
  • Jonathan2708Jonathan2708 Member Posts: 552
    I had this problem, you need to add the following to the OnBeforeImportRecord() trigger of your Dataitem :

    CLEAR(Rec);


    Your autoincrement field will then work fine.

    Jonathan
Sign In or Register to comment.