Importing from Text File

bekio
Member Posts: 204
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;
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;
0
Answers
-
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...0
-
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;0 -
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.0 -
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.
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", too0 -
Also, i have tried to delete this orders from table directly in NAVISION, and it quits navision without any warning or any message.0
-
-
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.0 -
I have solved this problem.
It seem to be my problem, so i solved by my self.
Thanks. \:D/0 -
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 thisCRONUS Singapore;2;Nama 2;Address 2
CRONUS Singapore;3;Nama 3;Address 3
how to solve this problem? thanks0 -
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.0 -
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 thisSFile.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 attachment0 -
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);0 -
And in the last line you don't have to use copystr, but instead just copy the value of field:
TestImport.Address:=FORMAT(vString);0 -
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 sameSFile.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');
0 -
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);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 error0 -
My mistake,
just use:
String:=DELSTR(vString,1,PosCode);
instead of
String:=DELSTR(vString,PosCode,1);
#-o0 -
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 thisSFile.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');
0 -
You are welcome,
Glad to help you,0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions