7 Replies Latest reply on Jul 4, 2016 1:41 AM by CICT

    Field Validation by Script - Global Field

    ChristofferRexen_1

      Hello everyone

       

      I am currently working on a database, which HR-Managers can access via WebDirect using login-information, to accede or resign employees.

      Now, based on my project description, a couple of the fields will have to be validated, which the HR-manager is prompted to enter before the record can be committed.

       

      Now, I am aware of FileMaker has it's own Field Validation, but it is not a secret it's bonkers..... (Sorry FileMaker..) 

       

      Therefore I was thinking of making a script to each of the different fields, which needs validation.

       

      Furthermore, I have made 6 possible option types for the HR-employees to enter data into, set by an unique ID, but with the use of the same fields.

       

      So...


      X fields with option type 1 (Accede)

      Y fields with option type 2 (Resign)

      Z fields with option type 3 (Maternity leave / leave)

      .. Etc. 6 option types in total.

       

      Question one; how do I do this, the most easily? Is it possible?

      I have 8 required fields for validation, fields are global.

      I don't want the scripts to interfere with the other option types, X, Y, Z, which each is set by an unique ID.

       

      Please see attached image of my setup.

        • 1. Re: Field Validation by Script - Global Field
          Mike_Mitchell

          ChristofferRexen_1 wrote:

           

          Now, I am aware of FileMaker has it's own Field Validation, but it is not a secret it's bonkers..... (Sorry FileMaker..)

           

           

          What makes you say that?

           

          Based on the image you posted, a simple "member of value list" validation would do what you want, What about that doesn't work?

          • 2. Re: Field Validation by Script - Global Field
            ChristofferRexen_1

            Maybe I am just frightened, because of previous attempts.


            I want the Error Message to pop-up, when a field is not validated in Danish, not English.

            - Is it even possible?


            Could you elaborate the "Member of value list", I'm kinda green in the more advanced FM-stuff.

            How do I do that?

             

            I am concerned that a field like annual salary, which is only to be filled in 3 or 4 of the option types, will prompt the user to be filled, although not possible since the field is not set to be visible in the, let's say "Resign" or "Maternity leave", where the HR-manager is then stuck?


            Or am I missing something?


            Please elaborate.


            Cheers

            • 3. Re: Field Validation by Script - Global Field
              Mike_Mitchell

              I'm not 100% certain what you mean by "field is not validated in Danish, not English". Do you mean you want the validation to fail if the person uses the wrong language?

               

              "Member of value list" is set in the validation options. In the Validation tab in the Options for the field, select "Member of value list":

               

              Screen Shot 2016-04-11 at 5.00.49 AM.png

               

              If you validate against the value list, then there shouldn't be an issue with either the language or with an empty field. Validation won't fire unless the user enters something (assuming you don't set the field as "Not empty"). Therefore, if the user can't see the field, then you don't have a problem. And if he enters a value that's not in the list - like a value in English instead of Danish - then the validation will fail, so you don't have to do anything fancy to account for language.

              • 4. Re: Field Validation by Script - Global Field
                ChristofferRexen_1

                If you validate against the value list, then there shouldn't be an issue with either the language or with an empty field. Validation won't fire unless the user enters something (assuming you don't set the field as "Not empty").

                The thing is, the specific fields must not be empty.

                If empty, FileMakers own pop-up dialog appears and prompts the user that X fields needs to be filled, before asking the user to either "Revert Field" (Nope, nope, nope), "No" (Just bypassing the required, still empty field), "Yes" (Re-enters the empty field).

                By danish, I mean that FileMakers own standard-dialog is popping up with english text, which I don't want to happen.


                That is also why I doubt "Member of a value list", will solve this problem.

                 

                That is why I thought about Script Triggers, to solve the problem, so when the user validates/exits the field, FileMaker will take a hold to the field, but only the given field, under the given option type:

                 

                X fields with option type 1 (Accede)

                Y fields with option type 2 (Resign)

                Z fields with option type 3 (Maternity leave / leave)

                .. Etc. 6 option types in total.

                 

                There has to be a better solution?

                • 5. Re: Field Validation by Script - Global Field
                  Mike_Mitchell

                  ChristofferRexen_1 wrote:


                  The thing is, the specific fields must not be empty.

                   

                   

                  This doesn't make sense. You can't require a field to be non-empty, and simultaneously not permit users to enter data into it. You will definitely get into a loop by doing that. Unless you put a default value in?

                   

                  By danish, I mean that FileMakers own standard-dialog is popping up with english text, which I don't want to happen.

                   

                  That's a function of your language settings when you installed FileMaker. You can probably fix it by going back and reinstalling it.

                   

                  That is why I thought about Script Triggers, to solve the problem, so when the user validates/exits the field, FileMaker will take a hold to the field, but only the given field, under the given option type:

                   

                  X fields with option type 1 (Accede)

                  Y fields with option type 2 (Resign)

                  Z fields with option type 3 (Maternity leave / leave)

                  .. Etc. 6 option types in total.

                   

                  There has to be a better solution?

                   

                  I still don't fully understand what you mean by this, but no, Script Triggers are never a good replacement for schema-level validation. They can be bypassed in many ways (import, data entry from layouts that don't have the trigger, etc.). You can use them as supplemental, if you want, but they should never be thought of as a primary or sole method for data integrity control.

                  • 6. Re: Field Validation by Script - Global Field
                    clayhendrix

                    Screen Shot 2016-07-03 at 5.14.35 AM.png

                    You can make it harder for users to bypass FileMaker's validation by UN-checking the "Allow user to override during data entry.

                     

                    I've unchecked that before and to the typical user, it seems impossible to move forward without using a value the FileMaker approves. It is CHECKED by default. So, you typically need to uncheck it to prevent users from overriding validation during data entry. Furthermore, leave the default selection of Always instead of Only during data entry, if you want FileMaker to validate the data more frequently than just when data is entered or modified.

                     

                    It's not in my image and it's sort of covered by a circle in Mike's image, but if you want to make certain that the field is not left blank or you ONLY want to make certain that the field is not left blank, you can check "Not Empty" under "Require:" on the validation tab we've been discussing.

                     

                    "Member of value list" is how I typically control validation as is in Mike's image in his original response.

                     

                    Also, why were you using Global Fields? If it were validation standards, I hope you would consider value lists.

                     

                    If you have figured out a solution, please mark this discussion answered and share what worked so that others who need help will know what worked for you.

                    • 7. Re: Field Validation by Script - Global Field
                      CICT

                      A little devil's advocate addition here. Although it is self evident that validation at field level is the most reliable way of enforcing business rules (as security is using FileMaker's built in security), it is also the least flexible and at times can cause major problems as we have limited control over when the validation is applied - for instance when accessing records with scripts in 'hidden' layouts the field validation can 'break' a script.

                       

                      Usually validation is required within selected layouts and, for this reason, we almost always script validation - this is also behind our requests to FMI for an OnRecordExit script trigger to mirror the way triggers on tabs work.

                       

                      Putting aside the normal scaremongering of 'what if someone has FMP Advanced and also knows your design level credentials' arguments that normally accompany this way of working, using separation we aim to keep the data files as 'dumb' as possible and have the interface file contain the business logic, which flies in the face of the field level validation.

                       

                      At times the business logic required can be so complicated (try writing an insurance management system) that it is almost impossible to piece together validation at field level, ideally validation should be applied at layout level.

                       

                      So for now we use global variables (or global fields if totally paranoid about security) and combinations of OnObjectEntry triggers to record initial values, OnObjectModify or OnObjectValidate (or Save) to apply the conditions of validation and OnObjectExit (or Save) to revert to the original value if necessary. We can also validate/control access to any object on a layout and the validation is only applied when required.

                       

                      The above allows us to use the structure of the interface file (which in turn allows us 60 second updates or rollbacks) and apply business logic only when it is required.

                       

                      Andy