OnModify trigger roll back

jordi79jordi79 Member Posts: 273
Hi All,

I did some coding in OnModify trigger of a table. This code will trigger an ERROR message based on certain conditions. Funny thing is, I found out that ERROR called from OnModify trigger does not trigger roll-back if the changes were done on an external table.

For example...
1) Code is written in OnModify of ITEM table to issue error message if "Description" field is not filled
2) I have written code to update an external table, when "Inventory Posting Group" is specified in Item Card. This code is written in OnValidate trigger of Item Table of "Inventory Posting Group" field
3) I created an item card record, specified "Inventory Posting Group", but did not specify "Description"
4) ERROR message from OnModify check is triggered, the changes to "Inventory Posting Group" in Item table is rolled back. but the changes to external table maintains. This change was not rolled back.

Any one can help out?

Comments

  • DenSterDenSter Member Posts: 8,304
    what do you mean by 'an external table'?
  • kinekine Member Posts: 12,562
    The OnValidate is called in separate transaction! It is why in many posts is written "do not change another table from OnValidate trigger". Do not forget, transaction flow is:

    1) User create record (OnNewRecord etc. on form is triggered)
    2) User enter value - OnValidate is called and when finishes, there is implicit commit=end of transaction...
    3) After user leave the record or move to another etc. the OnInsert or OnModify is called and when finishes, there is implicit commit.

    If you call Validate from code, it will be processed under one transaction with rest of your code, but when called from form by user data input, it is separate transaction...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • jordi79jordi79 Member Posts: 273
    then I would say that, it is a definite NO NO to put an ERROR message in OnModify trigger...
  • kinekine Member Posts: 12,562
    jordi79 wrote:
    then I would say that, it is a definite NO NO to put an ERROR message in OnModify trigger...
    No, that's not true... just move the code updating the second table into OnInsert and OnModify...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • jordi79jordi79 Member Posts: 273
    Hi Kine,

    Yes. then that would work. Actually, I have written some functions to make certain fields mandatory based on a setup table. And this code will call ERROR() from GLOBALINSERT and GLOBALMODIFY. This feature will apply to all tables in NAV.

    So to make this work, I would then have to modify all validations from OnValidate to OnModify. Seems unrealistic. I guess, it will be back to drawing board.

    Thanks anyway.
  • kinekine Member Posts: 12,562
    That's why something like "mandatory" fields are better solved by another way as described in many posts about mandatory fields.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • David_SingletonDavid_Singleton Member Posts: 5,479
    kine wrote:
    That's why something like "mandatory" fields are better solved by another way as described in many posts about mandatory fields.

    Yeah but you know that until they try it for themselves and after some months and a lot of user complaints they wont listen. ](*,)
    David Singleton
Sign In or Register to comment.