mibuso.com

Microsoft Business Solutions online community
It is currently Wed May 22, 2013 8:08 pm

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: [Solved] Importing from Text File
PostPosted: Mon Nov 22, 2010 11:05 am 
Offline

Joined: Thu Feb 18, 2010 11:21 am
Posts: 197
Country: Belgium (be)
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;


Top
 Profile E-mail  
 
 Post subject: Re: Importing from Text File
PostPosted: Mon Nov 22, 2010 11:10 am 
Offline

Joined: Wed Apr 11, 2007 12:07 pm
Posts: 167
Location: Barcelona
Country: Spain (es)
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...


Top
 Profile  
 
 Post subject: Re: Importing from Text File
PostPosted: Mon Nov 22, 2010 11:34 am 
Offline

Joined: Thu Feb 18, 2010 11:21 am
Posts: 197
Country: Belgium (be)
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;


Top
 Profile E-mail  
 
 Post subject: Re: Importing from Text File
PostPosted: Mon Nov 22, 2010 12:47 pm 
Offline

Joined: Thu Feb 18, 2010 11:21 am
Posts: 197
Country: Belgium (be)
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.


Top
 Profile E-mail  
 
 Post subject: Re: Importing from Text File
PostPosted: Mon Nov 22, 2010 1:14 pm 
Offline
MVP Microsoft Dynamics NAV

Joined: Mon Dec 11, 2006 10:34 am
Posts: 2863
Location: Bergamo
Country: Italy (it)
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


Top
 Profile  
 
 Post subject: Re: Importing from Text File
PostPosted: Mon Nov 22, 2010 1:17 pm 
Offline

Joined: Thu Feb 18, 2010 11:21 am
Posts: 197
Country: Belgium (be)
Also, i have tried to delete this orders from table directly in NAVISION, and it quits navision without any warning or any message.


Top
 Profile E-mail  
 
 Post subject: Re: Importing from Text File
PostPosted: Mon Nov 22, 2010 1:18 pm 
Offline
MVP Microsoft Dynamics NAV

Joined: Mon Dec 11, 2006 10:34 am
Posts: 2863
Location: Bergamo
Country: Italy (it)
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


Top
 Profile  
 
 Post subject: Re: Importing from Text File
PostPosted: Mon Nov 22, 2010 1:28 pm 
Offline

Joined: Thu Feb 18, 2010 11:21 am
Posts: 197
Country: Belgium (be)
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.


Top
 Profile E-mail  
 
 Post subject: Re: Importing from Text File
PostPosted: Mon Nov 22, 2010 3:20 pm 
Offline

Joined: Thu Feb 18, 2010 11:21 am
Posts: 197
Country: Belgium (be)
I have solved this problem.
It seem to be my problem, so i solved by my self.

Thanks. \:D/


Top
 Profile E-mail  
 
 Post subject: Re: Importing from Text File
PostPosted: Thu Dec 08, 2011 10:00 am 
Offline

Joined: Wed Sep 29, 2010 3:18 am
Posts: 764
Country: Australia (au)
i use your code
Code: Select all
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 :
Quote:
CRONUS Singapore;2;Nama 2;Address 2;
CRONUS Singapore;3;Nama 3;Address 3;


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


how to solve this problem? thanks


Top
 Profile E-mail  
 
 Post subject: Re: Importing from Text File
PostPosted: Thu Dec 08, 2011 10:21 am 
Offline

Joined: Thu Feb 18, 2010 11:21 am
Posts: 197
Country: Belgium (be)
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.


Top
 Profile E-mail  
 
 Post subject: Re: Importing from Text File
PostPosted: Thu Dec 08, 2011 10:33 am 
Offline

Joined: Wed Sep 29, 2010 3:18 am
Posts: 764
Country: Australia (au)
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
Code: Select all
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


Attachments:
error.jpg
error.jpg [ 26.57 KiB | Viewed 1267 times ]
Top
 Profile E-mail  
 
 Post subject: Re: Importing from Text File
PostPosted: Thu Dec 08, 2011 10:48 am 
Offline

Joined: Thu Feb 18, 2010 11:21 am
Posts: 197
Country: Belgium (be)
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);


Top
 Profile E-mail  
 
 Post subject: Re: Importing from Text File
PostPosted: Thu Dec 08, 2011 10:50 am 
Offline

Joined: Thu Feb 18, 2010 11:21 am
Posts: 197
Country: Belgium (be)
And in the last line you don't have to use copystr, but instead just copy the value of field:

TestImport.Address:=FORMAT(vString);


Top
 Profile E-mail  
 
 Post subject: Re: Importing from Text File
PostPosted: Thu Dec 08, 2011 10:53 am 
Offline

Joined: Wed Sep 29, 2010 3:18 am
Posts: 764
Country: Australia (au)
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
Code: Select all

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');


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum


Search for:
Jump to: