Options

not able to capture the error

Hi All,
I getting the following error message when i try to capture the error while transferring of data from one field to other field whose datatype lengths are different .I want to capture the error in a separate field .


totable.DELETEALL;
fromtable.RESET;
fromtable.FINDFIRST;
REPEAT
totable.INIT;
totable.TRANSFERFIELDS(fromtable);
totable.INSERT;
MESSAGE(FORMAT('Error Successfully Captured'));
IF NOT errorcapture1.RUN(fromtable) THEN
totable.errortable :=COPYSTR(GETLASTERRORTEXT,250);
totable.INSERT;
//errorcapture2.RUN;
UNTIL fromtable.NEXT =0;
when i was running i got the following error mesage.








Microsoft Dynamics NAV Classic
The following C/AL functions can be used only to a limited degree during write transactions because one or more tables will be locked.

Form.RunModal is not allowed in write transactions.

CodeUnit.Run is allowed in write transactions only if the return value is not used. For example, 'OK := CodeUnit.Run()' is not allowed.

Report.RunModal is allowed in write transactions only if 'RequestForm = FALSE'. For example, 'Report.RunModal(...,FALSE)' is allowed.

DataPort.RunModal is allowed in write transactions only if 'RequestForm = FALSE'. For example, 'DataPort.RunModal(...,FALSE)' is allowed.

Use the COMMIT function to save the changes before this call, or structure the code differently.

OK

Answers

  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,503
    start the debugger and see from where you are getting error
  • Options
    AKAK Member Posts: 226
    The error message already explains it:
    CodeUnit.Run is allowed in write transactions only if the return value is not used.
    .
    .
    .
    Use the COMMIT function to save the changes before this call, or structure the code differently.
    

    Insert a commit before
    IF NOT errorcapture1.RUN(fromtable) THEN
    
    but be aware that there is no roll back if another error occurs. All records will be written permanently until this point.
  • Options
    RockWithNAVRockWithNAV Member Posts: 1,139
    USE COMMIT, it will solve your case.
  • Options
    bharathnanbharathnan Member Posts: 92
    Hi mohana after running the debugger its throwing error here
    IF NOT errorcapture1.RUN(fromtable) THEN

  • Options
    ta5ta5 Member Posts: 1,164
    I'm not 100% sure, but I think in this type of a call to a codeunit, the debugger stops when finding an error. Without debugger it works as designed, meaning the caller of the codeunit handles the error.
  • Options
    bharathnanbharathnan Member Posts: 92
    rz1usnzaf2p7.png
    pyvz0cdtkq63.png
    7mqhdec13ed6.png
    wmt09lo8s7hg.png
    y0j44ann5r7c.png
    0sz3zjbf7u0m.png

    I did the following things to capture the error in nav using getlasterrortext but its throwing some error which i Have posted above.Please provide me some help..
    Warm regards,
    Bharath.K
  • Options
    HannesHolstHannesHolst Member Posts: 119
    FromTable.RESET;
    FromTable.FINDFIRST;
    REPEAT
      IF NOT ErrorCapture.RUN(FromTable) THEN
        BEGIN
          ToTable.INIT;
          ToTable.Field1 := 'prim_key';
          ToTable.ErrorText := COPYSTR(GETLASTERRORTEXT, 1, MAXSTRLEN(ToTable.ErrorText));
          ToTable.INSERT;
        END;
    

    The message says: Do not do any write-transactions to the database before calling "ErrorCapture.RUN" or when you have to do it, put a COMMIT before "ErrorCapture.RUN".
  • Options
    bharathnanbharathnan Member Posts: 92
    FromTable.RESET;
    FromTable.FINDFIRST;
    REPEAT
      IF NOT ErrorCapture.RUN(FromTable) THEN
        BEGIN
          ToTable.INIT;
          ToTable.Field1 := 'prim_key';
          ToTable.ErrorText := COPYSTR(GETLASTERRORTEXT, 1, MAXSTRLEN(ToTable.ErrorText));
          ToTable.INSERT;
        END;
    

    The message says: Do not do any write-transactions to the database before calling "ErrorCapture.RUN" or when you have to do it, put a COMMIT before "ErrorCapture.RUN".

    Thanks Hannes Its working for me .. thanks a lot
  • Options
    bharathnanbharathnan Member Posts: 92
    bharathnan wrote: »
    FromTable.RESET;
    FromTable.FINDFIRST;
    REPEAT
      IF NOT ErrorCapture.RUN(FromTable) THEN
        BEGIN
          ToTable.INIT;
          ToTable.Field1 := 'prim_key';
          ToTable.ErrorText := COPYSTR(GETLASTERRORTEXT, 1, MAXSTRLEN(ToTable.ErrorText));
          ToTable.INSERT;
        END;
    



    Without using the code given below is it possible to get the error captured,Since here we are hardcoding the value to the particular field
    ToTable.Field1 := 'prim_key';
    any suggestions please advice
Sign In or Register to comment.