5 Replies Latest reply on Mar 5, 2010 8:08 AM by LeoB

    Script to prevent leaving a field blank

    LeoB

      Title

      Script to prevent leaving a field blank

      Post

      In a new record layout, on the name field in the layout I have a script triggered OnObjectExit.  It's a tabbed field on the layout.

       

      The script is:

       

           If [Is Empty (Activity::ActivityName)]

               Beep

               Show Custom Dialog

               Go to Field [Activity::ActivityName]

           End If

       

      When a user does not complete the field and attempts to tab out of it or go to another field, the beep and custom dialog work, but then the user is taken to the next tabbed item instead of returning to the ActivityName field.  I tried moving the Go to Field line after End If, but no change.

       

      How would I write this script so that the user absolutely positively cannot go anywhere else until the field is filled in?

       

      Many thanks.

       

       

       

        • 1. Re: Script to prevent leaving a field blank
          ninja

          You could do this by field validation instead and type in your dialog there.  No need for a script to do this.

           

          Set your validation to "Not Empty" and fill in the dialog box at the bottom for what to say if validation fails.

          • 2. Re: Script to prevent leaving a field blank
            LeoB

            Ninja:

             

            Thanks for the quick response.  I should have mentioned that I tried that option first, but decided to go with a script because the layout is designed to not save changes automatically.

             

            On this layout I want the user to fill it in completely and, when the user is happy with it, then there's a Save Record button to click with a dialog box to remind the user that the record cannot be deleted by the user and will go for manager approval.  There WILL be the tendency by the user to make many mistakes on initial data entry.

             

            Using Field Validation doesn't pop up the dialog until the user tries to commit the record -- my objective, if possible, is to not let the user get out of that field until a name is entered.

             

            Maybe this isn't possible?

             

            Thanks again.

            • 4. Re: Script to prevent leaving a field blank
              raybaudi

              Hi

               

              you'll need another step:

               

              If [Is Empty (Activity::ActivityName)]

                       Beep

                       Show Custom Dialog

                       Exit Script [ Result: 0 ]

              End If

               

              A more general script, valid for any field, can be:

               

              If [ IsEmpty ( GetActiveFieldContents ) ) ]
                  Show Custom Dialog [ "Attention" ; "The field " & Get ( ActiveFieldName )  & " can't be empty" ]
                  Exit Script [ Result: 0 ]
              End If

               

              • 5. Re: Script to prevent leaving a field blank
                LeoB

                Jade and Raybaudi:

                 

                Both of your replies got me to the right place.  I would have never come up with that ExitScript step.

                 

                This will be very useful in a number of layouts.

                 

                And, the link that Jade pointed me to also answered some of my GoToField problems in other scripts.

                 

                Many thanks -- Mille grazie