2 Replies Latest reply on Jul 9, 2014 10:24 AM by deathrobot

    Script Trigger validation

    deathrobot

      Title

      Script Trigger validation

      Post

           Hi. Having trouble with the following. In one table I have a field that has its validation set to require a unique value. I use a custom dialog plugin and would like to have this show instead of Filemaker's default in the event of a duplicate value. I am trying to call a script that is:

           Set Error Capture [On]
           If [Get ( LastError ) <> 0]
                Show Custom Dialog
           End If

           I need to trigger this from a script trigger. I have tried every one, and in every case FM's default validation dialog shows before this script is run. Is there a way to do this using FM's validation? Or does it require turning that off and creating a scripted validation?

           Thanks!

           Michael

        • 1. Re: Script Trigger validation
          philmodjunk

               Get ( LastError ) only references the error code returned by the immediately preceding script step. (Better error handling is one of the items I requested very recently, see: http://forums.filemaker.com/posts/56b3613440 )

               Since the preceding script step is Set Error Capture [on] and it does not generate an error, Get ( LastError ) is always returning a zero.

               Get ( LastError ) also only returns error codes from script steps, not invalid data in a field.

               So it would appear that you need to use a different expression than Get ( LastError )  in order to get the results that you need.

               If you have a unique values validation set on the field where you are checking for unique values, you might try this code:

               Commit Records [No dialog]
               If [Get ( LastError) > 0 ]

          • 2. Re: Script Trigger validation
            deathrobot

                 Thanks for the solution and the explanation, Phil. That solved it.

                 Michael