How to role back a transcation when an error occurs

zimworxcodezimworxcode Member Posts: 53
edited 2011-10-13 in NAV Three Tier
I am designing an application that will create nav documents. I have noticed that after an INSERT command if an error occurs the inserted record remains... this is dangerous as the users of the application may post a redundant document. I need an application that will determine whether a transaction has been successful and that there has been no error only then will it create a Document, otherwise it has to abort the whole transaction. How do i structure my application to achieve this?

Comments

  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Check whether you have used COMMIT anywhere after the insert
  • bbrownbbrown Member Posts: 3,268
    Are we talking about NAV code here? Or an external application writing to NAV (directly or via Web Services)?
    There are no bugs - only undocumented features.
  • zimworxcodezimworxcode Member Posts: 53
    It a program in NAV. I am new to NAV development but i notice the journal posting and document posting, if anything wrong occurs the whole transaction is not posted at all. that is the same concept i am trying to use... if anything wrong occurs then no document should be created at all
  • bbrownbbrown Member Posts: 3,268
    The question above about COMMIT is applicable.

    NAV uses implicit transactions. That is you don't need to explicitly begin a transaction. The transaction ends (is committed) when either callign function ends, or an explicit COMMIT command is called. A transaction begins when a database write occurs (insert, modify, delete). In the case of a FINDSET(TRUE) the transaction begins with the select.

    In the event of an error, NAV will rollback the current active transaction. So the question becomes, is there prior commits beign executed?
    There are no bugs - only undocumented features.
  • zimworxcodezimworxcode Member Posts: 53
    Thank you for your response. I have not used any COMIT but i notice that if an error occurs after executing INSERT a record would have been created already which is not what i want.
  • kinekine Member Posts: 12,562
    And it means, that there is COMMIT used somewhere between the INSERT and the ERROR (like in OnInsert trigger etc.).
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • pdjpdj Member Posts: 643
    You can find the COMMIT using the Client Monitor. (Assuming you can reproduce the situation)

    NAV also issues a COMMIT if you use the returnvalue from a CODEUNIT.RUN or REPORT.RUN.
    Typically in an IF CODEUNIT.RUN("My Codeunit",MyRecord) THEN... structure.
    Regards
    Peter
Sign In or Register to comment.