11 Replies Latest reply on Mar 22, 2017 7:42 AM by beverly

    Beware when testing the success of a commit record

    Fred(CH)

      Hi there,

       

      Just wanted to share a recent experience.

       

      Since 9 years, when within a script, an intermediary validation was necessary, for instance when i had to Go to Layout or so on, i wrote this :

       

      Commit Records/Requests

      If [ Get ( LastError ) = 0 ]

         Go to Layout or all other stuff…

       

      I recently realised that it was not 100% reliable. Suppose that one field value does not match with its validation rules, and a "OnObjectEnter" Script is triggered on this field. When a field validation fails, FileMaker brings the focus to the first faulty field and thus, it potentially fire this script. If the last step of this one does not contain any error, it will clear the error result and obviously (always obvious after...) the test quoted above will result True even though the commit failed, and then, the Go to Layout step fails, and if the following steps are not so secure, you could come to a nightmare, as you probably might know.

       

      Since i understood that, i found that a simple change on my habits could help in most common situations : instead of testing the error code after the commit step, just test the actual record state :

       

      Commit Records/Requests

      If [ Get ( RecordOpenState ) = 0 ]

        Go to Layout or all other stuff…

       

      To who that may concern…

       

      Bye, Fred