9 Replies Latest reply on Mar 16, 2011 3:52 AM by Frinholp

    OnObjectValidate Script Trigger

    Frinholp

      Title

      OnObjectValidate Script Trigger

      Post

      I am trying to use the OnObjectValidate script trigger to perform a script if a validation error occurs.

      I have set a field to validate unique values only.

      This following script is attached to that field's OnObjectValidate script trigger.

      Set Error Capture [On]

      If [ Get (LastError) = 504 ]

      Show Custom Dialog [ "My Dialog" ]

      Exit Script [FALSE]

      EndIf

      My Script is triggered when a non-unique value has been entered in the field but the IF condition is never met. therefore the native uniqueness validation dialog is displayed.

      What am I doing wrong?

      Thanks in advance

      Lee

        • 1. Re: OnObjectValidate Script Trigger
          philmodjunk

          I don't think the error is thrown until after this 'event' is processed. I believe, from what I read in FileMaker help, that that this trigger "fires" before the field is actually validated.

          You may need to either stick with a custom validation error message in field options, come up with a different test to catch the unique values error in your script shown above, or possibly remove the unique values validation rule and use a test with a self join relationship based on the unique value field to identify the error when the field is saved, exited, or when the record is comitted.

          • 2. Re: OnObjectValidate Script Trigger
            Frinholp

            Thanks Phil

            use a test with a self join relationship based on the unique value field  to identify the error when the field is saved, exited, or when the  record is comitted.

            That is what I am currently doing so I can display my own dialog.

            I am trying to improve my scripts to make them more re-usable. My intentions was to append checks for error codes 500-507 to the code above so I could use native validation rather than running my own validation scripts. I thought if i could pull it off, that I could simply attach the one script to every field's OnObjectValidate script trigger allowing faster development.

            If I use the self-join I will need to reference the name of the self-join TOC therefore requiring a seperate script for every field that requires a unique value.

            Lee

            • 3. Re: OnObjectValidate Script Trigger
              philmodjunk

              You might be able to reference that self Join TO with Get Field and the name of the TO passed as a script parameter. (You can also just pass the value of the TOC::Field as the parameter.)

              Still not as nice as your original concept, but more portable than the literal reference to the field and table occurrence.

              • 4. Re: OnObjectValidate Script Trigger
                Frinholp

                I was thinking along those lines.

                I would need a script individual to a paticular field to call my unique test script with parameters as I can't simply call the unique script with parameters when attaching it to a script trigger.

                Not quite as sleek as I would've liked.

                Thanks again

                Lee


                • 5. Re: OnObjectValidate Script Trigger
                  philmodjunk

                  Why can't you specify the parameter when you set up the trigger?

                  Set Script Triggers allows you to specify a calculation for passing a parameter just like you can with Perform Script.

                  • 6. Re: OnObjectValidate Script Trigger
                    Frinholp

                    Oops! So you can.

                    I also never knew you could assign multiple scripts too.

                    I have been creating a parent script and performing script1, script2, script3........ etc

                    Always learning Embarassed

                    • 8. Re: OnObjectValidate Script Trigger
                      philmodjunk

                      A good article on the subject. If you paste a link to another location here, the forum software will convert it into a live link if you then place the cursor to the right of the last character of the the link and press return. (You can also use the Chain Icon to turn any selected text in your message into a live link to somewhere's else if you want.)

                      I edited your post to do that so it's easier for others to open up the article and read it.

                      • 9. Re: OnObjectValidate Script Trigger
                        Frinholp

                        Cheers Phil

                        I thought it maybe useful if someone is searching the forums for Script Triggers. Has a good flow chart to illustrate the order of execution of object script triggers and conditions required for a trigger to fire.

                        Two diagrams, one for FM10 users and one for FM11 users with the OnObjectValidate included.

                        Lee