4 Replies Latest reply on Aug 16, 2017 6:46 AM by afwalton

    Script to Check for Empty Fields

    sydbarker

      I am trying to create a script that essentially will check the entire record for empty fields, instead of having it validate each field individually. The script I have written is;

       

      If[IsEmpty(Personnel::ContactName  xor  IsEmpty(Personnel::Company) xor  IsEmpty(Personnel::Address) xor IsEmpty(Personnel::Title) xor IsEmpty(Personnel::Relationship) xor IsEmpty(Personnel::CompPhone) xor IsEmpty(Personnel::CellPhone) xor IsEmpty(Company::Market) xor IsEmpty(Company::RelationshipEst) xor IsEmpty(Personnel::Work6Mo) xor IsEmpty(Personnel::PriorityGrade) xor IsEmpty(Personnel::Relationship) xor IsEmpty(Personnel::Contract) xor IsEmpty(Personnel::DecisionMaker))

      Show Custom Dialog["Empty Fields"; "You have one or more empty fields on the current record. Please return and complete the record entirely."]

           If[Get(LastMessageChoice] = 1]

                Go to Previous Field

           End If

      End If

       

      I have the script trigger set to OnLayoutExit, but when exiting the layout, the script shows nothing. Any tips?

        • 1. Re: Script to Check for Empty Fields
          FileKraft

          XOR is not correct - please use OR instead because XOR uses mutual exclusive true ..

          • 2. Re: Script to Check for Empty Fields
            siplus

            Your UX translates into letting the user go wild on a form, which is a plus, but then coitus interruptus while getting an error message which

             

            1) frustrates, as being in contrast with the perceived freedom;

            2) forces him to reread all he entered in order to find what's wrong.

             

             

            A wise use of auto entering defaults + signaling the problem as soon as it arises (field validation) will lead to a IMHO better user experience.

            • 3. Re: Script to Check for Empty Fields
              ninja

              Or at the least...conditionally format the fields red to show them what's missing...

               

              I typically will have the "check script" look for empties...set a trap field (not on the layout) to "Empty", then conditionally format the entry fields to turn red if both

              1. The field is empty and

              2. The trap field is not empty.

               

              This makes the fields turn red only after they try to leave...but turns them red so they know what's missing.

              You can put that trap field on the layout itself if you like, setting it to "Please complete the data in the red fields" or some such...

               

              A string of fields all with "Not Empty" validation starts throwing error messages just by clicking outside the fields (ie. on commit)...my users find that even more annoying...

              HTH

              • 4. Re: Script to Check for Empty Fields
                afwalton

                I know that your post is relatively old, but I found it recently, it answered my question and inspired me.

                 

                Here is what I did after reading your post.

                I am posting it in case it is useful for anyone else.

                 

                For any table and layout where I want to make sure that certain fields are completed, that table has two fields:

                 

                (Table)::RequiredFields  - This field is a Text field, with Global Storage.

                (Table)::CompletenessChecker - This field is a Text Field.

                 

                The "RequiredFields" field is put on a System Administrator Layout. On that layout, the Administrator has listed the fields that are required for that table and each field is separated by a semi-colon. All fields with required fields are managed from this layout. The table name is not necessary, only the field name. For example, "BookedDate; Salesperson;".

                 

                When the user tries to submit the form, or tries to leave the layout, I perform a Script which calls a subscript named "SetCompletenessChecker" before it does its other work.

                The CompletenessChecker is entirely generic and can work for any of my layouts. The whole Script is the following: Screen Shot 2017-08-16 at 9.28.07 AM.png

                If the CompletenessChecker finds that a field listed in RequiredFields is empty, the text "Please complete the highlighted fields and then try to submit the form again." appears at the top of the layout and the empty fields are then highlighted in red using the following formula: "IsEmpty ( Self ) and not IsEmpty ( [TableName]::CompletenessChecker)". (For the conditional formatting, it appears to require a constant name for the table. This is easy enough to accommodate for.)

                 

                Here is an image result of highlighted fields:

                Screen Shot 2017-08-16 at 9.34.49 AM.png

                 

                If the user tries to leave the layout, the CompletenessChecker script is ran; if fields were left empty, the user will be notified that the record will be deleted if they leave without finishing the record. If they chose to stay, leaving the layout is halted by using "Exit Script Text Result: False". If they chose to leave, the record is deleted.