GETLASTERRORTEXT - How to use - How to set up the system

Steffen_BrodowskiSteffen_Brodowski Member Posts: 20
Hello!

Does anybody know, how the new function "GETLASTERRORTEXT" in Nav 5.0 is to handle?

Onlinehelp is showing as follows:

"Use this function to return the text that was contained in the last error message displayed by the system."

Comments of the helping:
"You can set up Microsoft Dynamics NAV so that it keeps running even if a runttime error occurs. You can use this function to find out whether or not an error has occurred and to see the actual text in the last error message that was generated."

So my question is: How to set up Navi, so there occurs no runtime error when an automationserver occurs an exeption?

Because its like an error in navi, witch will close forms, if it occurs at the OnOpenForm trigger for example but the begin of the error message is: "This message is for C/Side developpers...."

Greetings
Steffen Brodowski

Comments

  • PerJuhlPerJuhl Member Posts: 55
    Hi

    From Batch post Salesordre:

    CLEARLASTERRORTXT;
    IF SalesPost.RUN("Sales Header") THEN BEGIN
    CounterOK := CounterOK + 1;
    ErrorTxtVar := 'Not a problem';
    IF MARKEDONLY THEN
    MARK(FALSE);
    END
    ELSE
    ErrorTxtVar := LASTERRORTXT; // Only LAST !!!!!!!!!!

    If Salespost.RUN fail the error will not display or stop the program,
    and you can not display the error.

    You can eg. make a list of errors on the Invoices that fail posting.

    This is now possibel with GETLASTERROR.

    BR Per
  • Miklos_HollenderMiklos_Hollender Member Posts: 1,598
    It does not seem to work... If I have a codeunit called Child which has one line of code - ERROR('Something'); and another codeunit called Parent which says:
    CLEAR(Child);
    IF NOT Child.RUN THEN BEGIN
      IF GETLASTERRORTEXT<>'' 
         THEN MESSAGE('First error returned from child: '+  GETLASTERRORTEXT);
      CLEARLASTERROR;
    END;
    
    CLEAR(Child);
    IF NOT Child.RUN THEN BEGIN
      IF GETLASTERRORTEXT<>'' 
         THEN MESSAGE('Second error returned from child: '+ GETLASTERRORTEXT);
      CLEARLASTERROR;
    END;
    

    then it does not work properly: it only displays the second one. Any ideas?

    Also I cannot find that example code in Batch Post Sales Orders but the reason could be that the version number says NAVW15.00,NAVGB4.00 - which means the UK localisation might be a mixture of NAV5 and NAV4.

    However, I found some example code in Codeunit 5304 Outlook Synch. Outlook Mgt. :
                IF NOT OSynchProcessLine.RUN THEN BEGIN
                  IF GETLASTERRORTEXT <> '' THEN
                    WriteErrorLog(
                      OSynchUserSetup."User ID",
                      EntityRecID,
                      'Error',
                      SynchEntityCode,
                      GETLASTERRORTEXT,
                      ErrorLogXMLWriter,
                      Container);
                  CLEARLASTERROR;
                  ErrorConflictBuffer.RESET;
                  ErrorConflictBuffer.INIT;
                  ErrorConflictBuffer."User ID" := UserID;
                  ErrorConflictBuffer."Record ID" := EntityRecID;
                  ErrorConflictBuffer."Search Record ID" := FORMAT(EntityRecID);
                  IF ErrorConflictBuffer.INSERT THEN;
                END;
    

    It's exactly the same as I'm trying to do above - if we assume it works, any ideas why the above one doesn't?
  • KYDutchieKYDutchie Member Posts: 345
    Hey Miklos,

    try it with the CONFIRM instead of the MESSAGE Dialog. MESSAGE will only execute at the end of a codeunit. (Don't ask me why) :?

    This code will work:

    CLEAR(child);
    IF NOT child.RUN THEN BEGIN
    IF GETLASTERRORTEXT<>''
    THEN IF CONFIRM('First error returned from child: %1',TRUE, GETLASTERRORTEXT) THEN;
    CLEARLASTERROR;
    END;

    CLEAR(child);
    IF NOT child.RUN THEN BEGIN
    IF GETLASTERRORTEXT<>''
    THEN IF Confirm('Second error returned from child: %1', TRUE, GETLASTERRORTEXT) THEN;
    CLEARLASTERROR;
    END;


    Hope this Helps,

    KYDutchie
    Fostering a homeless, abused child is the hardest yet most rewarding thing I have ever done.
  • kinekine Member Posts: 12,562
    try it with the CONFIRM instead of the MESSAGE Dialog. MESSAGE will only execute at the end of a codeunit. (Don't ask me why)

    To not pause the running transaction and prevent long lock waiting times. It will be BIG disaster if Message stop transaction processing like CONFIRM... :whistle:

    (it was big problem in older versions where MESSAGE in some situations blocked the transaction... imagine process - e.g. batch posting - which shows message "Posting done" at the end of 30 minutes of running, when user is away for a break, and all others are waiting till he return and click the OK button...)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Miklos_HollenderMiklos_Hollender Member Posts: 1,598
    Thanks, it works. Interesting. In other situations, like when I'm messaging out some sort of debugging value when posting an order of five lines, all five messages promptly come up and the end of the transaction. In this case actually it has nothing to do with GETLASTERRORTEXT - even without it only the second MESSAGE is shown. i.e.
    IF NOT Child.RUN THEN BEGIN
         MESSAGE('First error returned from child: ') ;
    END;
    
    IF NOT Child.RUN THEN BEGIN
         MESSAGE('second error returned from child: ') ;
    END;
    
    

    This is really interesting and I think the reason might be that there must be some sort of MESSAGE cache and when we run the codeunit the second time it's getting cleared up.

    Anyway, it means that the important thing, the GETLASTERRORTEXT works this way. What I'm doing is that I'm loading and posting Output Journals from an external shop floor application via appserver. And if the journal posting goes tits up, I'll skip that one and send the last error text to the internal IT via e-mail. That's seriously cool that this is now possible - that almost looks like a real server-side application, not just a GUIless client :)
  • dakyndakyn Member Posts: 36
    If you try with Dialog object, you could have a dialog ever open and value of Text Cont linked on dialog ever active.
    DIALOG.OPEN('Status: #1######################');
    
    IF NOT Child.RUN THEN BEGIN 
         DIALOG.UPDATE('First error returned from child: ') ; 
    END; 
    
    IF NOT Child.RUN THEN BEGIN 
         DIALOG.UPDATE(1,'second error returned from child: ') ; 
    END
    
    DIALOG.CLOSE;
    

    And so on..... :)
  • kinekine Member Posts: 12,562
    Thanks, it works. Interesting. In other situations, like when I'm messaging out some sort of debugging value when posting an order of five lines, all five messages promptly come up and the end of the transaction. In this case actually it has nothing to do with GETLASTERRORTEXT - even without it only the second MESSAGE is shown. i.e.
    IF NOT Child.RUN THEN BEGIN
         MESSAGE('First error returned from child: ') ;
    END;
    
    IF NOT Child.RUN THEN BEGIN
         MESSAGE('second error returned from child: ') ;
    END;
    
    

    This is really interesting and I think the reason might be that there must be some sort of MESSAGE cache and when we run the codeunit the second time it's getting cleared up.

    Anyway, it means that the important thing, the GETLASTERRORTEXT works this way. What I'm doing is that I'm loading and posting Output Journals from an external shop floor application via appserver. And if the journal posting goes tits up, I'll skip that one and send the last error text to the internal IT via e-mail. That's seriously cool that this is now possible - that almost looks like a real server-side application, not just a GUIless client :)

    Yes, there is Message stack which is displayed on end of the transaction to prevent locking (only Confirm will block the transaction). And clearing the stack is one "small" bug (or feature?).
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.