4 Replies Latest reply on Dec 30, 2013 10:00 AM by ChrisJohnston

    Best practice for history script

    ChrisJohnston

      Title

      Best practice for history script

      Post

           I have a field that I have put a OnObjectExit Script. This field I am using to record history (in my HISTORY table) with Get(ActiveFieldName) and Get(ActiveFieldContents). I changed to OnObjectExit because I could not get anything out of OnObjectSave, probably because it being a post type step it is not getting to send the data before leaving the page. So OnObjectExit seems to work well, except I have to add a extra Go to Field step in a lot of the scripts that will trigger the OnObjectExit script. What I mean is, if I do the creation of a record manually it works, but when another script should trigger it because of new record creation nothing seems to happen. Is adding this extra Go to Field prudent? Am I going about the correct way?

        • 1. Re: Best practice for history script
          philmodjunk

               I think you need to describe the details of what you are trying to do here.

               OnObjectSave will work for this and should be the better trigger to use. Just clicking into and out of a field will trip OnObjectExit and this will perform your script even though no change was made to the data.

               And when I set an OnObjectExit trigger on a field and create a new record--either by keyboard shortcut or performing a script, I still am able to trip the script trigger.

          • 2. Re: Best practice for history script
            ChrisJohnston

                 But I am not clicking is the problem, the field has the script trigger waiting, if I click OnObjectSave works every time. I am expecting a script that creates a new record to do the same, but I think the problem for OnObjectSave is the script that is accessing the field is not recognizing the entry to it and then a save. Or I am not understanding/knowing that a script will not trigger a field save. I want to use OnObjectSave but I cant get it to fire this way. In another script it performs a Set Field on the field with the script trigger, but it seem to have no effect. I even do a Commit Records and nothing. However if I manually do it by clicking it works. Thanks

            • 3. Re: Best practice for history script
              philmodjunk

                   To repeat: I think you need to describe the details of what you are trying to do.

                   Scripts only trip script triggers if they interact with the layout or a layout object in some way. Some scripts can modify data without tripping a script trigger on the field as they can modify the data at the data level--bypassing any interaction with the layout's field object where you set a script trigger. This is normally a good thing as a script's inadvertently tripping a trigger is a major headache in FileMaker development.

                   Set field, for example modifies data at the data level and thus will not trip any script triggers.

                   Insert Calculated Result, on the other hand, will trip script triggers set on the field object.

                   But I must also point out that if you are using a script to modify the data and you want that change logged in your history, you don't have to trip a script trigger to do so. Your script can both modify the data and log the needed info in your history without ever tripping the trigger.

              • 4. Re: Best practice for history script
                ChrisJohnston

                     Boom!

                     

                          Set field, for example modifies data at the data level and thus will not trip any script triggers.

                     That is exactly the information I need to know. The other part make a lot of sense also, I am going to work on it. Excellent! Thanks