GETLASTERRORTEXT returns nothing with XMLport

bhalpin
Member Posts: 309
Hi.
I'm calling an XMLPort from a codeunit and I want to catch cases where the XMLPort fails because of a badly formed file, a condition I haven't forseen, etc.
So I have this:
The trouble is, ErrorText (returned by GETLASTERRORTEXT) is always empty, even in cases where a straight call to the XMLPort (no IF at the front) produces a proper NAV error message on the screen.
Has anyone got a suggestion why I can't get the error text properly?
Thanks in advance.
Bob
I'm calling an XMLPort from a codeunit and I want to catch cases where the XMLPort fails because of a badly formed file, a condition I haven't forseen, etc.
So I have this:
IF NOT XML_Port.IMPORT THEN BEGIN ErrorText := GETLASTERRORTEXT; CLEARLASTERROR; END; MESAGE(ErrorText);
The trouble is, ErrorText (returned by GETLASTERRORTEXT) is always empty, even in cases where a straight call to the XMLPort (no IF at the front) produces a proper NAV error message on the screen.
Has anyone got a suggestion why I can't get the error text properly?
Thanks in advance.
Bob
0
Answers
-
Hello, You need call a codeunit and inside the codeunit call the xmlport
your CU is going to look like this
onRun()
XML_Port.IMPORT;
your code will look like this
IF NOT MyCodeUnit.run THEN BEGIN
ErrorText := GETLASTERRORTEXT;
CLEARLASTERROR;
END;
MESAGE(ErrorText);0 -
Thanks ara3n .
Did that, and I think I'm good.
When the XMLport is called on a mal-formed XML file, I am now getting a proper (well, for NAV) error message on the screen, the code continues, and the error text is availble for logging just as I wanted.
I find it strange that the XML error makes it to the screen, but since this will be running under NAS I'm assuming that GUI error message will end up in the event log and not affect the processing.
Thank's again.
Bob
[/b]0 -
If you want it in the event log, I would more info such as the file name etc.
Most customers prefer to send an email or write it to a log table so that the can go and see it instead of logging where nas is to trouble shoot the problem.0 -
Yup. Agreed. Doing that.
I already have everything possible going to a plain-text log file, and I have email alerts going out reporting any errors in the imported data. (That's always the first code I write - I consider it essential for both development/debugging, and in production.)
This was all fine if the XMLport.IMPORT completed, but what was missing was the ability to report cases where the XMLport choked on a badly formed file and all processing ground to a halt. Now I have that covered as well.
Thank's again
Bob0 -
I see. Well good luck. and you are welcome.0
-
Will rise this old topic
Any ideas how to handle XMLPort malformed file error in case when XMLport is used as parameter for Web service?0 -
Yes as suggested by Rashed Ahmed Amini you need to restructure your code.
In NAV we have just Codeunit.Run where we can handle these type of requests.Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/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