1 2 Previous Next 16 Replies Latest reply on Feb 26, 2017 7:11 PM by philmodjunk

    Script Trigger on Record Exit?

    MarkBanin

      Hi

       

      Using FM Pro 14

       

      I need to do a check (script trigger) when exiting a record - by exiting a record I mean:

       

      1) navigating to a different record

      2) changing layout

      3) closing the database

       

      I'm pretty sure I know how to deal with 2) and 3)  but not 1)

       

      Anyway of doing this?

       

      Thanks

       

      Mark

        • 1. Re: Script Trigger on Record Exit?
          rgordon

          Is there a pattern to the different record you want to go? There are script steps to take you to specific records. The pattern determines what script step to use.

          • 2. Re: Script Trigger on Record Exit?
            globe11123

            You could apply some of the check code you are using on your script triggers to navigation buttons.

             

            It all depends how you navigate through your layouts.

            • 3. Re: Script Trigger on Record Exit?
              CICT

              Mark

               

              This is a missing feature we've added to the suggested features and have had long debates with other developers here. I'll try to find our posting and add a link here later.

               

              Time and time again we've needed this missing script trigger for validation purposes, so nice to see someone else raising it.

               

              Kind regards

              Andy

              • 4. Re: Script Trigger on Record Exit?
                ErikWegweiser

                I accomplish this using the OnRecordCommit trigger.

                Yes, it means automatically opening the record OnRecordLoad.

                I set a $$variable flag to allow or disallow committing the record.

                Disallowing prevents moving to a different record, layout, etc.

                1 of 1 people found this helpful
                • 5. Re: Script Trigger on Record Exit?
                  CICT

                  That is an approach Erik and I don't know how you're using the $$variable. However, we are usually looking to give the user every opportunity to enter all data, including committing the record until they are ready to leave it and then invoke some validation.

                   

                  From memory the OnPanelSwitch runs this way, so it shouldn't be a huge job to implement, but would make a huge difference to us.

                   

                  Regards

                  Andy

                  1 of 1 people found this helpful
                  • 6. Re: Script Trigger on Record Exit?
                    ErikWegweiser

                    Andy,

                    I often use this technique in a 'modal' dialog (i.e., when the user clicks on an "Edit" button). This changes a boolean $$allow_record_commit flag to 0; The Edit layout has an OnRecordCommit trigger. The triggered script checks the flag and prevents the commit step if it isn't 1. The "Done" button on the layout performs business logic (within a validation loop) before setting the flag to 1 and attempting to commit and leave or close the dialog. Incidentally, after the business logic and attempt to commit, I capture any validation errors and reset $$allow_record_commit to 0 if any occur. And yes, there may be additional business logic after that. There may also be a "Cancel" button on the layout that might perform a revert, depending on how I've set up the dialog.

                    1 of 1 people found this helpful
                    • 7. Re: Script Trigger on Record Exit?
                      CICT

                      Thanks Erik

                       

                      Yes, that makes perfect sense but does rely on a button or modal window. Our problem has always been using the top left navigation in a normal layout, of which there are three ways (four if you count forward and back as 2) a user can move from one record to another.

                       

                      By using OnRecordCommit you risk the user's workflow constantly being interrupted, and the potential of them losing data already input and we don't want to turn FileMaker's standard way of saving data automatically off, as in the majority of cases it is exactly what we need.

                       

                      Most of the applications we're writing are enforcing business logic and procedures and this is a big omission from the suite of tools available to us, particularly when you look at the OnObject suite of triggers, which does have this option.

                       

                      Regards

                      Andy

                      • 8. Re: Script Trigger on Record Exit?
                        MarkBanin

                        Thanks for all the replies.  It's really quite surprising that this isn't here.  You would've thought it's an important feature.  Now I've got to find all the different ways of navigating elsewhere and script them...lol....It feels like I'm going back to the dark ages...haha

                         

                        Navigation wise, most of the time a user will use a google style search box to navigate to a different record but what happens if they use the "record" menu to navigate away.....hmph

                         

                        Scripting everything that can navigate away doesn't sound right....I think I'll have to come up with an alternative.

                        • 9. Re: Script Trigger on Record Exit?
                          HammerOz

                          I need this. I simply want a silent script deleting a record on exit if it hasn't been confirmed. I don't want any user interruption. I want to let them add a tentative record where the expectation is the record wont exist unless they hit confirm. I would use on record exit all  the time as a clean and easy record clean up , revert changes solution.

                          • 10. Re: Script Trigger on Record Exit?
                            philmodjunk

                            Except for closing a window or exiting the layout, exiting a record means entering another record. Therefore, OnRecordLoad can be used to check the previous record.

                             

                            First, set up a self join to your layout's table:

                            YourTable::gPreviousRecordID = YourTable 2::__pkYourTableID

                             

                            gPreviousRecordID would be a global field.

                             

                            Your script would look like this:

                            If [$$TriggersOff ]

                               Exit Script [. ]

                            End If

                             

                            If [ not IsEmpty ( $$PreviousID ) ]

                                Set Field [ YourTable::gPreviousTecordID ; $$PreviousID ]

                                 //put your code to validate the previous record here. reference YourTable 2 to do so.

                            End If

                            Set Variable [ $$PreviousID ; YourTable::__pkYourTableID ]

                             

                            To delete a record, you could set $$TriggersOff to True, then use the self join with Go To Related Records to open a new window where you delete the record, reset the variable to null or false and close the window. This window can be opened off the monitor edge to keep it hidden.

                            1 of 1 people found this helpful
                            • 11. Re: Script Trigger on Record Exit?
                              CICT

                              A good idea Phil, but in my opinion there are just too many ways of leaving a record: menus, layout menus, entering Find mode, etc. This method would have to have an OnLayoutEntry trigger in every layout in a solution to be partially effective, whereas a single OnRecordExit trigger on the layout in question would remove all these flawed work arounds.

                               

                              The fact that we have other 'OnExit' triggers, this seems an obvious requirement, particularly when enforcing organisational procedures.

                               

                              Kind regards

                               

                              Andy

                              • 12. Re: Script Trigger on Record Exit?
                                philmodjunk

                                I was not suggesting that a new trigger wouldn't be helpful, just pointing out that there are ways to do it with what we have now.

                                 

                                I see no need for OnLayoutEnter, but do see a need for OnLayoutExit and OnWindowClose. This was addressed earlier so my answer focused on changing records in the same layout and window.

                                You do make a good point about changing mode, but returning to Browse Miode trips OnRecordLoad so my method should still work. All menu options that I can think of will trip one of those three triggers.

                                 

                                But in most cases, this is doing it the hard way. The need to validate a record "on exit" implies that the user has edited the record. In such cases, OnCommitRecord usually does what is needed. The usual issue with it is when a user "prematurely commits" by clicking the layout background. There are several design options, however, that can prevent that.

                                • 13. Re: Script Trigger on Record Exit?
                                  CICT

                                  I agree Phil, but constantly coding compromises isn't satisfying or productive. It really is horses for courses and the assumption that a user would always input the whole information before committing a record isn't often the case (try entering a healthcare group insurance policy covering a hundred plus employees).

                                   

                                  We encourage the use of commit record at regular intervals for obvious reasons. However, overuse of validation at this stage can interfere with the workflow, and yes there are techniques to help, but they do not cover every eventuality.

                                   

                                  I think we're all in agreement that certain methods can help, but also that we're all working around an omission from our toolbox.

                                   

                                  Regards

                                  Andy

                                  1 of 1 people found this helpful
                                  • 14. Re: Script Trigger on Record Exit?
                                    HammerOz

                                    Thanks Phil,

                                     

                                    I have implemented this. I have to move this work flow to ipad layouts so it might slide panel triggers might add some ideas for my needs too.

                                    1 2 Previous Next