Options

Importing from Text File

bekiobekio Member Posts: 204
edited 2011-12-08 in NAV Three Tier
Hello Everyone,

I have a serious problem.
I have a text file(field delimiter= '|') that i have to import it to NAV.
I import this text file in to Sales Header(as order), and all the validation are ok. But if i trie to delete this order
it quits(navision closes) me out from NAVISION without any warning. Below are the strucure of text file and codeunit that i have done to import that text file. I can post the order without any problem. I also have made a dataport to import this text file into NAV, and it is importet and you can delete it without any problem.

Can some body tell me when i am wrong, or making mistake.

Thanks.



Sales Header text file whith to rows
D10|30|D10|19/11/2010||1||5
D10|31|D10|19/11/2010||1||10



IF FileCreated.OPEN(Path+'Headers.txt') THEN
BEGIN
FileCreated.CREATEINSTREAM(InstreamObj);
//InstreamObj.READTEXT(Rreshtitxt,1024);
WHILE NOT (InstreamObj.EOS) DO
BEGIN
MaxLength:=InstreamObj.READTEXT(Rreshtitxt,1024);
PikeOccurence:=STRPOS(Rreshtitxt,'|');
SalesHeader.RESET;
SalesHeader.INIT;
SalesHeader."Document Type":=2;

// GET e lokacionit - jo real
SHLocations:=COPYSTR(Rreshtitxt,1,PikeOccurence-1);
Rreshtitxt:=DELSTR(Rreshtitxt,1,PikeOccurence);

//GET No te fatures
PikeOccurence:=STRPOS(Rreshtitxt,'|');
SHNo:=FORMAT(COPYSTR(Rreshtitxt,1,PikeOccurence-1));
Rreshtitxt:=DELSTR(Rreshtitxt,1,PikeOccurence);
IF SHNo<>'' THEN
BEGIN
SalesHeader."Document Type":=1;
SalesHeader.VALIDATE(SalesHeader."Document Type");
SalesHeader."No.":=SHNo;
SalesHeader.VALIDATE(SalesHeader."No.");
SalesHeader."No. Series":='SO';
SalesHeader."Posting No. Series":='SI';
SalesHeader."Shipping No. Series":='SS';
END;


//GET Lokacionit real
PikeOccurence:=STRPOS(Rreshtitxt,'|');
SHLocations:=COPYSTR(Rreshtitxt,1,PikeOccurence-1);
Rreshtitxt:=DELSTR(Rreshtitxt,1,PikeOccurence);


//GET Dates se fatures
PikeOccurence:=STRPOS(Rreshtitxt,'|');
EVALUATE(SHPostingDate,COPYSTR(Rreshtitxt,1,PikeOccurence-1));
Rreshtitxt:=DELSTR(Rreshtitxt,1,PikeOccurence);
IF SHPostingDate<>0D THEN
BEGIN
SalesHeader."Posting Date":=SHPostingDate;
SalesHeader.VALIDATE(SalesHeader."Posting Date");
SalesHeader."Document Date":=SHPostingDate;
SalesHeader.VALIDATE(SalesHeader."Document Date");
SalesHeader."Order Date":=SHPostingDate;
SalesHeader.VALIDATE(SalesHeader."Order Date");
SalesHeader."Shipment Date":= SHPostingDate;
SalesHeader.VALIDATE(SalesHeader."Shipment Date");
END;
SalesHeader."Sell-to Customer No.":=Klienti;
SalesHeader.VALIDATE(SalesHeader."Sell-to Customer No.");

SalesHeader."Location Code":=Lokacioni;
SalesHeader.VALIDATE(SalesHeader."Location Code");


// GET Sales Person-it
PikeOccurence:=STRPOS(Rreshtitxt,'|');
SHSalesPerson:=FORMAT(COPYSTR(Rreshtitxt,1,PikeOccurence-1));
Rreshtitxt:=DELSTR(Rreshtitxt,1,PikeOccurence);
IF SHSalesPerson<> '' THEN
BEGIN
SalesHeader."Salesperson Code":=SHSalesPerson;
SalesHeader.VALIDATE(SalesHeader."Salesperson Code");
END;

//GET Sell To Customer No
PikeOccurence:=STRPOS(Rreshtitxt,'|');
SHSelltoCustomer:=COPYSTR(Rreshtitxt,1,PikeOccurence-1);
Rreshtitxt:=DELSTR(Rreshtitxt,1,PikeOccurence);


//GET User Code Loged In
PikeOccurence:=STRPOS(Rreshtitxt,'|');
SHUserCodeLogedIn:=FORMAT(COPYSTR(Rreshtitxt,1,PikeOccurence-1));
Rreshtitxt:=DELSTR(Rreshtitxt,1,PikeOccurence);
SalesHeader."User Code Loged in":=FORMAT(SHUserCodeLogedIn);

//GET Invoice Discount %
//PikeOccurence:=STRPOS(Rreshtitxt,'|');
EVALUATE(SHInvoiceDiscount,Rreshtitxt);
Rreshtitxt:=DELSTR(Rreshtitxt,1,PikeOccurence);
IF SHInvoiceDiscount<>0 THEN
BEGIN
SalesHeader."Invoice Discount Calculation":=1;
SalesHeader.VALIDATE(SalesHeader."Invoice Discount Calculation");
SalesHeader."Invoice Discount Value":=SHInvoiceDiscount;
SalesHeader.VALIDATE(SalesHeader."Invoice Discount Value");
END;
IF NOT SalesHeader.INSERT THEN SalesHeader.MODIFY;
END;
FileCreated.CLOSE;
END;

Answers

  • Options
    crisnicolascrisnicolas Member Posts: 177
    Have you used the debugger while deleting to identify at which point the process crashes? This may give you a hint on what is going wrong...
  • Options
    bekiobekio Member Posts: 204
    yes it stops at codeunit 99000855 Planning - Get Parameters\GetMfgSetup()
    And when i pres F5 it closes the NAV.

    GetMfgSetUp()
    IF NOT HasGotMfgSetUp THEN
    HasGotMfgSetUp := MfgSetup.GET;
  • Options
    bekiobekio Member Posts: 204
    Also to be mentioned.
    I have created a codeunit in NAV, and it can delete orders imported from text file.
    In Sales Order form i can delete only the orders that are created in Sales Order form, or imported from dataport.
    But still i can not delete those orders imported by codeunit.
  • Options
    BeliasBelias Member Posts: 2,998
    bekio wrote:
    Also to be mentioned.
    I have created a codeunit in NAV, and it can delete orders imported from text file.
    In Sales Order form i can delete only the orders that are created in Sales Order form, or imported from dataport.
    But still i can not delete those orders imported by codeunit.
    i think (but i hope not) that in your codeunit you run something like
    Salesheader.DELETE;
    this doesn't fire the ondelete trigger in the table (but you must run it!).
    If you instead correctly wrote Salesheader.DELETE(TRUE) there can be something written in the ondelete trigger of the FORM (that is not run from the codeunit, because you're firing the ondelete of the table with delete(true).
    anyway, you have to investigate your debugger with the use of the "call stack", too
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • Options
    bekiobekio Member Posts: 204
    Also, i have tried to delete this orders from table directly in NAVISION, and it quits navision without any warning or any message.
  • Options
    BeliasBelias Member Posts: 2,998
    bekio wrote:
    Also, i have tried to delete this orders from table directly in NAVISION, and it quits navision without any warning or any message.
    then, it's clearly something in the ondelete trigger...
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • Options
    bekiobekio Member Posts: 204
    In codeunit i have just puted SalesHeader.Delete(TRUE), and it quits me from NAVISION.
    This situation is geting harder, and i am been confused now. Why to quit NAVISION without any warning, without stoping at some points.
  • Options
    bekiobekio Member Posts: 204
    I have solved this problem.
    It seem to be my problem, so i solved by my self.

    Thanks. \:D/
  • Options
    julkifli33julkifli33 Member Posts: 1,073
    i use your code
    OnRun()
    SFile.TEXTMODE(TRUE);
    SFile.WRITEMODE(FALSE);
    SFile.OPEN('D:\TestImport\Test.txt');
    REPEAT 
    SFile.READ(vString);
    PosCode:=STRPOS(vString,';');
    TestImport.No := FORMAT(COPYSTR(vString,1,PosCode-1));
    vString:=DELSTR(vString,1,PosCode);
    
    PosCode:=STRPOS(vString,';');
    TestImport.Name := FORMAT(COPYSTR(vString,1,PosCode-1));
    vString:=DELSTR(vString,1,PosCode);
    
    PosCode:=STRPOS(vString,';');
    TestImport.Address := FORMAT(COPYSTR(vString,1,PosCode-1));
    vString:=DELSTR(vString,1,PosCode);
    
    TestImport.INSERT;
    UNTIL
    SFile.POS = SFile.LEN;
    MESSAGE('Import Done');
    

    but the for each of line must end with ";"
    example :
    CRONUS Singapore;2;Nama 2;Address 2;
    CRONUS Singapore;3;Nama 3;Address 3;

    but my sample data is like this
    CRONUS Singapore;2;Nama 2;Address 2
    CRONUS Singapore;3;Nama 3;Address 3

    how to solve this problem? thanks
  • Options
    bekiobekio Member Posts: 204
    String:=DELSTR(vString,1,PosCode);

    If your line in .txt file does not end with ';' than for the last field you don't have to use delstr, but just get the value of that field.
  • Options
    julkifli33julkifli33 Member Posts: 1,073
    bekio wrote:
    String:=DELSTR(vString,1,PosCode);

    If your line in .txt file does not end with ';' than for the last field you don't have to use delstr, but just get the value of that field.

    my code already block 1 line like this
    SFile.TEXTMODE(TRUE);
    SFile.WRITEMODE(FALSE);
    SFile.OPEN('D:\TestImport\Test.txt');
    REPEAT 
    SFile.READ(vString);
    PosCode:=STRPOS(vString,';');
    TestImport.No := FORMAT(COPYSTR(vString,1,PosCode-1));
    vString:=DELSTR(vString,1,PosCode);
    
    PosCode:=STRPOS(vString,';');
    TestImport.Name := FORMAT(COPYSTR(vString,1,PosCode-1));
    vString:=DELSTR(vString,1,PosCode);
    
    PosCode:=STRPOS(vString,';');
    TestImport.Address := FORMAT(COPYSTR(vString,1,PosCode-1));
    //vString:=DELSTR(vString,1,PosCode);
    
    TestImport.INSERT;
    UNTIL
    SFile.POS = SFile.LEN;
    MESSAGE('Import Done');
    

    but still have error message
    please take a look at my attachment
  • Options
    bekiobekio Member Posts: 204
    you have some mistake on your written code, the syntax for Delstr is ok, but as i saw you have to put PosCode, as the second parameter, not the third.
    Here is the syntax:

    NewString := DELSTR(String, Position [, Length])

    And this should be like this.
    vString:=DELSTR(vString,PosCode,1);
  • Options
    bekiobekio Member Posts: 204
    And in the last line you don't have to use copystr, but instead just copy the value of field:

    TestImport.Address:=FORMAT(vString);
  • Options
    julkifli33julkifli33 Member Posts: 1,073
    bekio wrote:
    you have some mistake on your written code, the syntax for Delstr is ok, but as i saw you have to put PosCode, as the second parameter, not the third.
    Here is the syntax:

    NewString := DELSTR(String, Position [, Length])

    And this should be like this.
    vString:=DELSTR(vString,PosCode,1);

    as you told me, i already reversed it
    but the error message is still the same
    SFile.TEXTMODE(TRUE);
    SFile.WRITEMODE(FALSE);
    SFile.OPEN('D:\TestImport\Test.txt');
    REPEAT 
    SFile.READ(vString);
    PosCode:=STRPOS(vString,';');
    TestImport.No := FORMAT(COPYSTR(vString,1,PosCode-1));
    vString:=DELSTR(vString,PosCode,1);
    
    PosCode:=STRPOS(vString,';');
    TestImport.Name := FORMAT(COPYSTR(vString,1,PosCode-1));
    vString:=DELSTR(vString,PosCode,1);
    
    PosCode:=STRPOS(vString,';');
    TestImport.Address := FORMAT(COPYSTR(vString,1,PosCode-1));
    vString:=DELSTR(vString,PosCode,1);
    
    TestImport.INSERT;
    UNTIL
    SFile.POS = SFile.LEN;
    MESSAGE('Import Done');
    
  • Options
    bekiobekio Member Posts: 204
    bekio wrote:
    And in the last line you don't have to use copystr, but instead just copy the value of field:

    TestImport.Address:=FORMAT(vString);
  • Options
    julkifli33julkifli33 Member Posts: 1,073
    bekio wrote:
    bekio wrote:
    And in the last line you don't have to use copystr, but instead just copy the value of field:

    TestImport.Address:=FORMAT(vString);
    Data :
    test code1;test name1;test address1
    test code2;test name2;test address2
    test code3;test name3;test address3

    Code :
    SFile.TEXTMODE(TRUE);
    SFile.WRITEMODE(FALSE);
    SFile.OPEN('D:\TestImport\Test.txt');
    REPEAT 
    SFile.READ(vString);
    PosCode:=STRPOS(vString,';');
    TestImport.No := FORMAT(COPYSTR(vString,1,PosCode-1));
    vString:=DELSTR(vString,PosCode,1);
    
    PosCode:=STRPOS(vString,';');
    TestImport.Name := FORMAT(COPYSTR(vString,1,PosCode-1));
    vString:=DELSTR(vString,PosCode,1);
    
    //PosCode:=STRPOS(vString,';');
    //TestImport.Address := FORMAT(COPYSTR(vString,1,PosCode-1));
    TestImport.Address := FORMAT(vString);
    //vString:=DELSTR(vString,PosCode,1);
    
    TestImport.INSERT;
    UNTIL
    SFile.POS = SFile.LEN;
    MESSAGE('Import Done');
    

    New error
  • Options
    bekiobekio Member Posts: 204
    My mistake,

    just use:
    String:=DELSTR(vString,1,PosCode);
    instead of
    String:=DELSTR(vString,PosCode,1);
    #-o
  • Options
    julkifli33julkifli33 Member Posts: 1,073
    bekio wrote:
    My mistake,

    just use:
    String:=DELSTR(vString,1,PosCode);
    instead of
    String:=DELSTR(vString,PosCode,1);
    #-o

    hi bekio
    now it works
    thanks a lot for your help
    the final code is like this
    SFile.TEXTMODE(TRUE);
    SFile.WRITEMODE(FALSE);
    SFile.OPEN('D:\TestImport\Test.txt');
    REPEAT 
    SFile.READ(vString);
    PosCode:=STRPOS(vString,';');
    TestImport.No := FORMAT(COPYSTR(vString,1,PosCode-1));
    vString:=DELSTR(vString,1,PosCode);
    
    PosCode:=STRPOS(vString,';');
    TestImport.Name := FORMAT(COPYSTR(vString,1,PosCode-1));
    vString:=DELSTR(vString,1,PosCode);
    
    TestImport.Address := FORMAT(vString);
    
    TestImport.INSERT;
    UNTIL
    SFile.POS = SFile.LEN;
    MESSAGE('Import Done');
    
  • Options
    bekiobekio Member Posts: 204
    You are welcome,

    Glad to help you,

    :D
Sign In or Register to comment.