7 Replies Latest reply on Jan 16, 2014 12:32 PM by philmodjunk

    "Go to Layout has been canceled." Script Error

    KenHoopes

      Title

      "Go to Layout has been canceled." Script Error

      Post

           Please assist,

           I am encountering an error where validation rules on the global fields used for a script attached to a button, do not prevent the script from launching, and allows for erroneous data. My example is below.

            

           I have two layouts (layouta and Layoutb).

           Layout A has 2 global fields (fielda and fieldb) each with validation rules and one button (buttona)

           Button A has the following script attached:

            

           Go To Layout["layoutb"(layoutb)]

           New Record/Request

           Set Field [layoutb::fielda; layouta::fielda]

           Set Field [layoutb::fieldb; layouta::fieldb]

           Commit Records/Requests[]

           Go to Layout [original layout]

            

           As long as the validation rules for the fields on "layouta" are met, the script runs without issue.

           If the validation rules are not met for one of the fields, but the user clicks "buttona" without removing focus from the field first, the validation error pops up with "Revert Field" and "Ok". If the user clicks "Revert Field" the script above continues to run, and duplicates the data in layoutb, which is not a desired result. If the user clicks "Ok" they are presented with a pop up that says "Go to Layout has been canceled. Do you wish to continue with this script?". From there any number of things can happen, but all of them undesirable.

            

           Is there a way that if field validation is not met, the script will just stop, or even a way that before the button can be clicked no fields can have focus.

           I'm not sure but any advice is appreciated.

        • 1. Re: "Go to Layout has been canceled." Script Error
          philmodjunk

               Validation rules have no effect on whether a script does or does not execute. The script would need to check the value of the field(s) to determine whether or not to run.

               I would take a look at the OnObjectValidation trigger as a way to perform a script that validates the data in the field and handles user errors in a more user friendly fashion. This script can use Exit Script [False] to keep the user action--clicking the button, that tripped the trigger from being processed by FileMaker.

          • 2. Re: "Go to Layout has been canceled." Script Error
            KenHoopes

                 Still no joy, through a number of configurations surrounding OnObjectValidation and Exit Script [False].

                  

                 Either i can get it to do nothing, or the original result, but not the desired result.

                  

                 I would think on object validation is what i want, but i need to prevent the button from being able to be pressed unless the field validates successfully.

            • 3. Re: "Go to Layout has been canceled." Script Error
              philmodjunk

                   Exit Script [False]

                   will prevent the button click.

              • 4. Re: "Go to Layout has been canceled." Script Error
                KenHoopes

                     If I just place Exit Script [False] in the OnObjectValidation trigger it prevents me from moving out of that box even when the value is correct.

                • 5. Re: "Go to Layout has been canceled." Script Error
                  philmodjunk

                       That is correct. You want to use this option for when you want to return the user to the field in order to correct it. So you use an If block where this is used to cancel out the button click when there is an error, but keep it from being executed when there is not an error.

                       Set Error Capture [on]
                       Commit Records
                       If [Get ( LastError ) // there was a validation error
                          Revert Records [no dialog ]
                          Show Custom Dialog ["there was a validation error"]
                     Exit Script [False]--> this step keeps the button click from being processed, but only if an error is detected
                       End If
                  If control passes to this part of the script, no error was detected and the button click event is processed.

                  • 6. Re: "Go to Layout has been canceled." Script Error
                    KenHoopes

                         One last weird thing that I am experiencing with this setup.

                         When I do click the button, it appears that all of the steps in the script activate, but then I get a pop-up asking me if I want to "Save changes to this record?" with options for dont save, save, and cancel.

                         If I do click save, I can effectively work around field validation and save a totally incorrect value.

                    • 7. Re: "Go to Layout has been canceled." Script Error
                      philmodjunk

                           Sounds like your layout is configured to disable automatic saves.. If so, use the "no dialog" option for commit records.