Throwing Errors in CU1 (3.70)

mark_aumark_au Member Posts: 40
Hi All, long time reader, first time poster here (edit: 2nd time apparently! can't remember posting anything else :?: ).

I've recently put some code in Codeunit 1 (the OnGlobal functions to be exact) which throws an error on a certain condition. Now whilst i've got the code working as required, i'm having a problem where the error message isn't displayed instantly, it waits for another trigger somewhere down the line (not exactly sure what the conditions are though) before it shows up.

For example, i've got code in the OnGlobalDelete function which throws an error on a certain condition when you delete a record. If i replicate that condition, the delete is stopped as though the error has been thrown, the debugger falls over on the error code, but the error isn't displayed until i either modify/insert/delete/close and reopen the form (possibly other conditions too, they are the only one's i've observed so far though).

I thought it may have something to do with the Changelog code in those triggers, so i modified my code so that the changelog code would not run when mine does, but that didn't help either.

Can anyone offer any advice as to why this might be happening?

Thanks,

Mark.

Comments

  • ara3nara3n Member Posts: 9,256
    Hello Mark

    Those triggers and all table triggers in Navision such as
    onmodify

    get triggered when you leave the record. (close form, pageup,pagedown to next record)


    oninsert get triggered when you leave the primary key field to nonprimary, unless delayed insert is set on the form.

    so your code will only trigger onglobal triggers at the same time.

    Also take a look at function
    GetGlobalTableTriggerMask in CU. this function calls changelog mgt and if you want all the global triggers to fire you need to with exit(15)

    If you could explain what you are trying to accomplish and why you would need the trigger to instantly fire when the user leaves a field.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • mark_aumark_au Member Posts: 40
    Hi ara3n,

    Thanks for the input. I have already modified the code (got my info from this thread), and it is all working as it should, however, my problem is that the error message is being displayed 1 "trigger" too late.

    I will try to clarify better with an example of what is happening, assume that i have it setup so that OnInsert, OnModify and OnDelete i get error messages saying "you cannot insert" (as well as modify/delete), and i follow this process:

    1. Change value of a record
    2. Move off record
    3. Record reverts to xRec (i.e. it is not modified)
    4. Move to new line (No error message has been displayed)
    5. Insert new record
    6. Error message "you cannot modify" is thrown (should have been displayed with step 3.)
    7. New record has not been inserted, still on new line.
    8. Move back to existing record
    9. Delete existing record
    10. Error message "you cannot insert" is thrown (should have been displayed at step 6.)
    11. Record has not been deleted.
    12. Modify existing record
    13. Record reverts to xRec (i.e. it is not modified)
    14. Error message "you cannot delete" is thrown (should have been displayed at step 10.)

    I am positive the code works correctly, as i put the debugger on and it fell over at the correct line of code, however, the first time it falls over it doesn't display an error message, and from then any further error message seems to be 1 behind.

    Anyway, it's not that big a deal as i have found another way to do what i'm trying to achieve, although it would be nice to find out why that was happening as i would have prefered to use the OnGlobalX functions rather than the way i'm doing it now (coding the insert/modify etc. triggers on all relevant tables).

    Thanks again!
  • ara3nara3n Member Posts: 9,256
    I can't recreate the issue in 4.x
    Can you try your code in 4.x executables?
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • kinekine Member Posts: 12,562
    This is well know behaviour. There is a :bug: (but not named as bug by MS) when you call Error in process started from CU1, the error is in a stack and is called one error message later. Some time before I found a workaround - just call message with the text and after that call error with empty text. It will show you the message with the error text and will rollback the transaction. There is just one difference - user will see Info icon instead Warnin Icon on the dialog.
    It means something like
      MESSAGE(Text000);
      ERROR('');
    
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.