How to intercept error message "IF Codeunt.run"

arcullarcull Member Posts: 191
Hi there. I wonder if it possible to get somehow the error string which terminates the running procedure in cases when you use
IF Codeunit.run(...
in batch posting for instance. Thanks for your help.

Comments

  • matttraxmatttrax Member Posts: 2,309
    Do you mean the GETLASTERRORTEXT function?
  • arcullarcull Member Posts: 191
    Do you mean the GETLASTERRORTEXT function?
    Something like that would be nice, but is any such command avaialable on nav 4.0? Thanks again.
  • MallyMally Member Posts: 128
    U can write error message in that codeunit which u r running on OnRunTrigger of that codeunit.
  • kinekine Member Posts: 12,562
    What about technical upgrade to NAV 5.0? Than you can use the new function as Mattrax wrote...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • MallyMally Member Posts: 128
    Dear Kine
    He wants to terminate the process.
  • kinekine Member Posts: 12,562
    Mally wrote:
    Dear Kine
    He wants to terminate the process.
    And? What do you want to tell by that? Have you read what he want? He want to catch the error message... :whistle:
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • arcullarcull Member Posts: 191
    What about technical upgrade to NAV 5.0? Than you can use the new function as Mattrax wrote...
    nope, that is not possible for now. But I thought of a soulution like this. First rewrite all errors like this, insted of using
    ERROR(Text013)
    
    , I would write
    ErrString := Text013;
    ERROR(ErrString);
    
    . Then write a function in CU to retrieve ErrString. And if the CU fails to run, I would call my new function. But that doesn't seem the best way :(
  • kinekine Member Posts: 12,562
    You cannot use it in this way directly - when you run the codeunit through CODEUNIT.RUN, you cannot call some specific function of the same instance of the codeunit. You will need to use Singleinstance CU. Do not forget that many things could happen in nested objects, through TESTFIELDS etc...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • arcullarcull Member Posts: 191
    You cannot use it in this way directly - when you run the codeunit through CODEUNIT.RUN, you cannot call some specific function of the same instance of the codeunit. You will need to use Singleinstance CU. Do not forget that many things could happen in nested objects, through TESTFIELDS etc...
    well this is not true, you can do it without any single instance cu. All you need is to declare the CU you are running and make sure the variables are global in that CU. But still this is not the method I want to use.
    OBJECT Codeunit 50001 Test Post
    {
      OBJECT-PROPERTIES
      {
        Date=24.02.10;
        Time=11:12:07;
        Modified=Yes;
        Version List=;
      }
      PROPERTIES
      {
        OnRun=BEGIN
                ErrStr := Text001;
                ERROR(ErrStr);
              END;
    
      }
      CODE
      {
        VAR
          Text001@1000000000 : TextConst 'ENU=This is the error message!';
          ErrStr@1000000001 : Text[100];
        ;
    
        PROCEDURE GetErrStr@1000000001() : Text[100];
        BEGIN
          EXIT(ErrStr);
        END;
    
        BEGIN
        END.
      }
    }
    
    OBJECT Codeunit 50002 Test Msg. Interception
    {
      OBJECT-PROPERTIES
      {
        Date=24.02.10;
        Time=11:15:04;
        Modified=Yes;
        Version List=;
      }
      PROPERTIES
      {
        OnRun=BEGIN
                IF NOT TestPostCU.RUN THEN BEGIN
                  ErrStr := TestPostCU.GetErrStr;
                  MESSAGE(ErrStr);
                END;
              END;
    
      }
      CODE
      {
        VAR
          TestPostCU@1000000000 : Codeunit 50001;
          ErrStr@1000000001 : Text[100];
    
        BEGIN
        END.
      }
    }
    
    
  • kinekine Member Posts: 12,562
    Ok, yes, this way it is possible...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.