11 Replies Latest reply on Aug 2, 2016 1:51 PM by BruceHerbach

    Script Trigger Validation

    alinicjones

      I need to run a script trigger validation on a form. I have a button on the layout that they click if they are ready to make this audit complete. I need the script trigger to check and make sure that all 4 fields are not empty before it will navigate them to another layout to "complete" the audit. The script that I have right now that is not working is:

       

      If (IsEmpty (Question1 and Question2 and Question3 and Question4) )

           Show Custom Dialog

      Else If (not IsEmpty (Question1 and Question2 and Question3 and Question4))

           New Window

           GoToLayout

      End If

       

      I can't use the field validation b/c they might come into this layout and exit out of it without answering these questions. The only time they have to have the questions answered is before they mark this audit complete. @

       

      If any of y'all have any ideas on this i would really appreciate it!! Thank you for your time!

        • 1. Re: Script Trigger Validation
          jsp
          20. OnLayoutExit Triggers a script to run before a layout is exited Layout Pre 11
          • 2. Re: Script Trigger Validation
            BruceHerbach

            A couple of items. 

             

            First when the script runs. Split the is empty up

             

            If( isempty(field1)  or isempty(field2) or isempty(field3) or isempty(field4)

             

            Then a dialog and exit script

             

            Else goto layout

             

            Second,  you probably don't want a new window. This leaves the record in the original window. Instead just change layouts.

             

            HTH

             

            Sent from my mobile device... Please excuse typos.

            • 3. Re: Script Trigger Validation
              mtwalker

              Try this instead:

               

              If [ IsEmpty (Question1) or IsEmpty (Question2) or IsEmpty (Question3) or IsEmpty (Question4) ]

                   Show Custom Dialog

                   Exit Script [False]

              Else

                   GoToLayout

              End If

               

              The Exit Script script step will stop whatever action they were trying to do to leave the layout, other after they dismissed the dialog they might be allowed to leave. You'll need run the trigger when they click the button and also on layout exit. I would recommend you hide the status area and use a custom menu to prevent the user from changing records or enter find mode which would allow them to bypass the validation.

              • 4. Re: Script Trigger Validation
                keywords

                Further to previous posts, note that both Bruce and Todd have used "or" rather than "and" as you did to join the conditions. If you use get the syntax right, as per both examples posted, and use "and" the test will only fail if all four fields are empty, whereas if you use "or" it will fail if any one of them is empty.

                • 5. Re: Script Trigger Validation
                  Malcolm

                  You might consider field validation because you have a clearly defined condition which can be tested which is that the user has decided the audit is complete. You could capture this decision using a field "isAuditComplete" that the user checks as a part of the sign-off or you could set the value when the user clicks the "done" button.

                   

                  Your field validation would be something like this:

                   

                  if ( isAuditComplete ;  not isEmpty( Self ) ; 1 )

                   

                  In a multi-layout form, if the field does not appear on the layout that the user is on when validation fails you get a error message. To provide a better UI you have to run the test yourself, so that you can navigate to the correct layout and select the field that needs input.

                  • 6. Re: Script Trigger Validation
                    alinicjones

                    Thank you, it works great now!

                    • 7. Re: Script Trigger Validation
                      erolst

                      keywords wrote:

                      use "and" the test will only fail if all four fields are empty, whereas if you use "or" it will fail if any one of them is empty.

                       

                      While it is important to know your Boolean or and and, FileMaker here allows for a neater method, using Count():

                       

                      not Count ( Question1 ; Question2 ; Question3 ; Question4 ) // equal to 'Count ( … ; … ) = 0'

                       

                      is True if none of the listed fields is non-empty (or simpler: all are empty), while

                       

                      Count ( Question1 ; Question2 ; Question3 ; Question4 ) ≠ 4

                       

                      is True if any field is empty (not all four are filled in).

                      • 8. Re: Script Trigger Validation
                        keywords

                        Nice!

                        • 9. Re: Script Trigger Validation
                          tackermax

                          This really worked great for me.  However, does anyone know how I would implement this with all my required fields in a portal?  This script works for the first row, but none of the following.

                          • 10. Re: Script Trigger Validation
                            SteveMartino

                            tackermax wrote:

                             

                            This really worked great for me. However, does anyone know how I would implement this with all my required fields in a portal? This script works for the first row, but none of the following.

                            How is the data getting into the portal in the first place?  Is it from an import, or is this a one time 'clean up data' event? 

                            The reason I ask is that under normal data entry you can't enter data in more than one portal row at a time, so data validation should be performed before you exit the portal row.

                            • 11. Re: Script Trigger Validation
                              BruceHerbach

                              Not quite sure how this fits into a portal.  But that stated you can loop through a portal.

                               

                              In Layout mode, give the portal an Object name.

                              Then:

                              Use GotoObject[ Objectnamehere ]

                              Go To Portal Row[1]

                              Loop

                                Do your check here

                                IF Fail test

                                  Possibly add a PopOver and open it here when validation fails to edit your selected record

                                  Pause script will user fixes issue

                                  Continue Script

                                  Close PopOver

                              End If

                              GoToPortalRow[ Next; Exit after last ]

                              end Loop

                               

                              HTH