Problem with code/messagebox, can you help?

ImaspalImaspal Member Posts: 68
Hi Experts!

I have a codeunit, that launches few codeunits. If any of these "codeunitlaunches" won't work, description of this "crash" is written to the error log. After "crash" next codeunit will be launched normally.

After a single codeunit is ready, the "Ready"-messagebox appears.

If there is no "crashes", my codeunit works fine.

If "crash" appear to one codeunit, the other codeunits run normally and error log is written ok.

The problem is with messageboxes. The system shows only messageboxes of the performed codeunits that are launched after "crash". It seems to be, that when data is written to the error log, all those messageboxes disappear, that appeared before crash.

Can you help with this problem?

Yours,
IP

Comments

  • kinekine Member Posts: 12,562
    Messages are saved into "stack" and are showed just at the end of transaction. If you have some error, this "stack" can be in your case cleared and thus no messages are showed. It is done in this way to prevent messages to block transactions by waiting for user input (if the message block the transactions, all locks on tables will be there until user click OK on the message and it can be few minutes after...). Try to solve the "messages" in another way. What is the purpose of these messages? Can you do same thing in another way?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • ImaspalImaspal Member Posts: 68
    Thanks, good questions.

    I haven't done those codeunits, so I'm not sure of their purpose. I guess they only report to user, that codeunit have been succesfully performed.

    Maybe you can give me a hint of how to do this in other way, if I show you my algorithm?

    Algorithm goes like this:
    No := 1;
    REPEAT
      Table.SETRANGE("Order No.", No);
      IF Table.FIND('-') THEN BEGIN
        REPEAT
          IF CODEUNIT.RUN(CodeunitID) = FALSE THEN BEGIN
            "writing data to error log" 
            COMMIT;
          END;
        UNTIL Table.NEXT = 0;
      END;
      No := No + 1;
    UNTIL No >= 5;
    

    Codeunits have to be performed in certain order. This order is in the Table. In this table user can change the order in which the codeunits are performed.

    Yours,
    IP
  • kinekine Member Posts: 12,562
    May be just instead error when run fails, you can add section which will write "OK" into the log... in this case you will have log for boths - fails and ok runs.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • ImaspalImaspal Member Posts: 68
    Messages are saved into "stack" and are showed just at the end of transaction. If you have some error, this "stack" can be in your case cleared and thus no messages are showed.

    Is it possible to clear this "stack" somehow, for example by code?

    Yours,
    IP
  • kinekine Member Posts: 12,562
    No, the stack is implemented internaly and you do not have any access to that.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • ImaspalImaspal Member Posts: 68
    No, the stack is implemented internaly and you do not have any access to that.

    So, if I want to clear the stack, I have to make a runtime-error on purpose and pass this error by if-sentence. Is it "clever/normal/acceptable" to make a runtime-error on purpose?

    Yours,
    IP
  • kinekine Member Posts: 12,562
    It is not "normal" to call error just to clear the message stack... ;-) Primary purpose of Error is to roll-back the transaction, not preventing to show some messages. You can use e.g. singleinstance codeunit to keep the message texts in some temporary table and read and show them when you need... it means "creating some own message stack which you have fully under control"... ;-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.