AnsweredAssumed Answered

Save Button / OnRecordCommit / Revert - Best Practices??

Question asked by dewitte on Aug 18, 2017
Latest reply on Aug 20, 2017 by dewitte

HI all.  I tracked down a bug in my save routine yesterday and in doing so, I uncovered some major flawed logic.  Without going into a lot of detail on the flawed part - I'll just say I had multiple commit statements both in my save script and my onrecordcommit script.  It seems that I was thinking you had to overtly execute the COMMIT statement during the onrecordcommit.  So IN my onrecordcommit script I had something like:


Do you want to save record?


   COMMIT; No Dialog




But in running the debugger, you actually see the commit trigger an onrecordcommit script.  At one point, I even had a nasty loop going.


The logic now works as follows (please let me know if I'm back on track):


Save Button Script:

Set var $$SavePressed=1  -- so we know the user initiated the save - and yes, I do reset this to zero (just not in this example)

Commit Records; No Dialog


OnRecordCommit Script:

If $$Savepressed=1

     run script that sets fields and does other updates based on what user has done

     exit script true


     dialog: "Do you want to save record or revert changes?"

     if save

          run script that sets fields and does other updates based on what user has done

          exit script true


          revert record  --------- is this correct?  because if I don't do this, the false exit leaves the record changed but not committed

          exit script false

      end if

end if


Now if a user moves off the record - it asks and the record gets committed.  If the user clicks save, it also commits.


My confusion is that I didn't realize commit had already started by the time you reached onrecordcommit and all you can do now is exit false to abort the commit.  I somehow, erroneously, thought that onrecordcommit was more of a "you are now taking over filemakers built-in commit function, so you have to manually execute the commit statement"


Follow-up / related question - In my data entry screen I have a portal linked to a global field in my main table.  If I alter the global field to update the portal, I've been adding a commit on my onobjectexit to update the portal because it seems that if I didn't commit the global field, the join didn't update. However, wouldn't this commit also trigger the onrecordcommit script?  I thought I needed this commit in order for the portal relationship to work.  (but I haven't retested this since I made the above changes)