GETLASTERRORTEXT returns nothing with XMLport

bhalpinbhalpin TorontoPosts: 292Member
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:
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

Answers

  • ara3nara3n Posts: 9,232Member
    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);
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • bhalpinbhalpin TorontoPosts: 292Member
    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]
  • ara3nara3n Posts: 9,232Member
    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.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • bhalpinbhalpin TorontoPosts: 292Member
    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

    Bob
  • ara3nara3n Posts: 9,232Member
    I see. Well good luck. and you are welcome.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ArmondsArmonds Posts: 61Member
    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?
  • RockWithNAVRockWithNAV Posts: 857Member
    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. :smile:
Sign In or Register to comment.