5 Replies Latest reply on Jul 28, 2014 10:21 AM by philmodjunk

    Exiting Script After Pressing Cancel

    JustinHesser

      Title

      Exiting Script After Pressing Cancel

      Post

           In my script I run an import and then run a bunch of other things after. What I want to know is how my script can automatically exit if I press cancel. I show an example of what  I see in the pictures attached. 

           If I click cancel on the top picture, the bottom picture comes up. What I would like to do (if possible) is to circumvent the second picture and just go straight to exiting the script.

           Please let me know if this is possible.

      2014-07-22_161605.jpg

        • 1. Re: Exiting Script After Pressing Cancel
          philmodjunk

               Put in

               Set Error Capture [on]

               Before the Import Records step.

               Then, if there is any scripting after Import Records that should not take place if the user cancels:

               Add this step:

               If [ Get ( LastError ) ]
                  Exit Script []
               End IF

               Immediately after the Import Records step to detect the fact that the user clicked cancel.

          1 of 1 people found this helpful
          • 2. Re: Exiting Script After Pressing Cancel
            JustinHesser

                 Thanks, Phil!

                 This code worked for that situation, but I have come into a new situation with the set error capture on.

                 As you can see in the attached image, I am trying to import new records.

                 This is my script currently:

            Set Error Capture [on]

            Import Records[...]

            If [ Get ( LastError ) ]

               Exit Script []
            End IF

                 What is happening is that I am avoiding the error message image#2 (which I want to do), but as a result, if there is a record that is skipped due to errors, as shown in the third picture, when I click OK, the script ends.

                 My ideal situation would be for there to be a way to exit the script if I click cancel and to continue if there are records skipped due to error.

                 Is there a way to do this? Or is there a different solution for this issue?

                  

            • 3. Re: Exiting Script After Pressing Cancel
              philmodjunk
                   

                        but as a result, if there is a record that is skipped due to errors, as shown in the third picture, when I click OK, the script ends.

                   The record was skipped but not because you clicked cancel. The import should not have taken place at all. The script is supposed to exit without importing records if the user clicks the cancel button.

                   Note. When a record is "skipped due to errors" this is typically due to a record not being imported because data in at least one field does not successfully pass a validation field option--such as a unique values option on an ID field.

              • 4. Re: Exiting Script After Pressing Cancel
                JustinHesser

                     I understand that, I guess I should've explained more clearly. 

                     If I click cancel when on the import screen, I want for the script to end and for the "Import Records has been cancelled. Do you wish to continue with this script?" screen not to come up. (Which is what currently happens)

                     But, if I click Import and then one or more of the records have fields with errors, I want the script to continue. But because I have Set Error Messages On, it catches the screen "Import Records Summary" as an error and ends the script.

                     I want the script to continue because I have pieces of the script later on that help me catch why the errors occurred.

                     What I want to know is if there is a way to catch the "Cancel" in the Import Field and end the script without using the Set Error Messages On function.

                • 5. Re: Exiting Script After Pressing Cancel
                  philmodjunk

                       Ok, then we just need to test for the specific error code:

                       If [ Get ( LastError ) = 1 // user clicked cancel ]

                       You can look up Error Codes in FileMaker help to get the complete list of values that this function can return.