1 2 Previous Next 25 Replies Latest reply on Jul 18, 2017 12:53 PM by wimdecorte

    When is commit record/request needed in a script?

    ezeitgeist

      When is Commit Record/Request needed in a script?

       

      I have been adding it after I create a new record within a script. But, if I just do a Find and set fields for an already existing record, do I need to Commit Record/Request?

       

      I've seen it used and not used in all situations so am curious what the standard protocol for use is so that I can at least be consistent.

        • 1. Re: When is commit record/request needed in a script?
          philmodjunk

          If you use it where it is not needed, generally no harm occurs so you often find it in script examples in places where it isn't strictly needed. Lot's of other actions in a solution either by user or a script automatically commit records so one normally does not need it until something fails to update or needs use updated info entered while in Browse mode and you find that you can't until you commit records.

           

          You don't need it while setting up a find request so it serves no purpose there.

          • 2. Re: When is commit record/request needed in a script?
            ChrisJohnston

            I always wondered this myself. I know one thing it does is move the focus away from the last field you were in. It leaves the record just sitting there like it has never been touched.

            • 3. Re: When is commit record/request needed in a script?
              philmodjunk

              Yes, you do have to be aware of this focus change and it can be a secondary reason for using the step.

               

              Actions that also commit records:

              Changing layouts

              Changing Mode (this is why you don't need it with finds)

              Changing records

              Closing the window

              Clicking a blank area of the layout.

               

              Can anyone think of another action that commits records without the explicit script step?

              • 4. Re: When is commit record/request needed in a script?
                ezeitgeist

                So if I do a Go to Layout and then a Find in a script, to get to a specific record, and then set fields in that specific record, do I need to Commit it at the end then before the script goes back to another layout?

                • 5. Re: When is commit record/request needed in a script?
                  gofmp15

                  I've advocated always using commit record at the end of creating and filling in a new record, etc.

                   

                  However, there are times when you may not want to commit the record and instead revert the record. You can't revert a committed record, only delete it. Deleting will cause problems with the sequence numbers of Get(recordid) and the IRS may wonder why so many records are missing, etc.

                   

                  That being said, there are times when not committing a record will lose data and those are always the time when I did not commit the record... 

                   

                  So, there's no perfect answer to your question but unless you have a real reason not to, do it.

                  • 6. Re: When is commit record/request needed in a script?
                    wimdecorte

                    philmodjunk wrote:

                     

                    If you use it where it is not needed, generally no harm occurs so you often find it in script examples in places where it isn't strictly needed. Lot's of other actions in a solution either by user or a script automatically commit records so one normally does not need it until something fails to update or needs use updated info entered while in Browse mode and you find that you can't until you commit records.

                     

                    I tend to favor defensive coding so I will commit explicitly when I am done modifying a record and I want to know whether my commit will hold *before* I take any other action.  That way I can trap for and handle any errors a little more easily and keep the code very readable.  Not a big fan of letting other actions doing something implicitly that I can do explicitly

                     

                    Another place where it can be extremely useful is if you modify a record, don't commit but then do an ExecuteSQL() against that table.  If you have a good number of records in that table your SQL query can be dog slow because of how FM behaves in this scenario.  So doing an explicit commit can help you out here.

                    • 7. Re: When is commit record/request needed in a script?
                      gofmp15

                      Agree wholeheartedly.

                       

                      I remember my first day on a Tandy and learning basic. I first wrote the hello world and alphabet pyrimid and then discovered loops, etc.

                       

                      After an exciting day of work and success, I turned off the computer.

                       

                      The next day, my program wasn't there and I learned what 'Save' meant... 

                       

                      Another issue is the modern technique of storing everything in memory and then flushing it to drive every 15 minutes. No number of commits will save data created during those 15 minutes...

                      • 8. Re: When is commit record/request needed in a script?
                        CarlSchwarz

                        Here's some reasons

                        - If you have a script that is operating on multiple windows then you have to commit the record in one window before editing the same record in another window, otherwise you will get "Record is locked by ...." error message.

                        - If you want to use the value from a calculation that is only evaluated when a record is committed

                        - If you want to free up a record in a multi user environment, your script may finish but not have committed the record that the script edited (be careful of single step triggers)

                        - I suggest committing at the end of a PSOS, scheduled server script or script called via remote API's (php etc.) because the record can remain locked to the server, I haven't fully tested when that one happens because I simply make sure I commit now.

                         

                        On the opposite side if you are in the situation where committing causes a lot of delay then you may want to be more frugal with the commit.  This can be more noticeable over a WAN.

                        • 9. Re: When is commit record/request needed in a script?
                          CarlSchwarz

                          gofmp15 wrote:

                           

                           

                          Another issue is the modern technique of storing everything in memory and then flushing it to drive every 15 minutes. No number of commits will save data created during those 15 minutes...

                          I guess you are talking about the "flush cache to disk" script step?  Though it doesn't work on server, just pro and go

                          • 10. Re: When is commit record/request needed in a script?
                            User20517

                            Hi, I want to cover one very important aspect of your question. philmodjunk has nicely listed all the actions that trigger an automatic commit. You absolutely MUST explicitely Commit before using any of these actions in your script if you modified the record. And you MUST check the error status before proceeding.

                            Because if your commit fails, so will the next action, yet your script goes on!

                             

                            And consistently, before you start modifying data in a script, you must execute Open Record/Request and properly handle a possible failure to do so.

                            • 11. Re: When is commit record/request needed in a script?
                              coherentkris

                              Just the checkbox inside the Show Custom Dialog script step.. but thats a step within a script.

                              Hmm wonder if Perform Quick Find script step perform a mode change thereby causing an implicit commit.

                              • 12. Re: When is commit record/request needed in a script?
                                gofmp15

                                Filemaker needs to implement what I used in 4D 20 years ago:

                                 

                                On error go sub

                                 

                                Or in FileMaker terms

                                 

                                On error perform script(script;error) The error parameter would be implicit in the function.

                                 

                                This would be added at the beginning of the script and any step that generated an error would then perform the stated script. This script could have nested ifs for each error and what to do if it occured.

                                 

                                This new function would eliminated having to capture the error after every important action in the script as FIleMaker would perform the script at any error other than 0.

                                • 13. Re: When is commit record/request needed in a script?
                                  ezeitgeist

                                  Open Record/Request?? Oh boy. I don't think I've ever used that. I usually go to the record, set the fields, and then sometimes Commit, sometimes not. Glad I asked. So I should be Open Record'ing every time BEFORE I change fields?

                                  • 14. Re: When is commit record/request needed in a script?
                                    wimdecorte

                                    If you want to know whether you can actually modify the record then yes.  You could do it after your Set Field too but that's not so 'clean'.  Either way, if the data is important then you have to check for errors one way or the other.

                                    1 2 Previous Next