6 Replies Latest reply on Sep 2, 2012 3:35 PM by Sorbsbuster

    Validate field on exit

    JamesHalliwell

      Title

      Validate field on exit

      Post

      Hi All

      Please could someone help me out with a script in the onobjectvalidate i am scanning barcodes into a form i need to check if the first two charaters of the barcode begin with +H or +M

      In access i achived this by putting in an after update event

      If Left([Barcode], 2) = "+H" Or Left([Barcode], 2) = "+M"  Then Exit Sub
      Beep
      Cancel = True
      Me.Barcode.Undo
      End Sub

      Please could someone help me convert this into filemaker script as i have only attended a one day course and scripts was not on it

       

      Many thanks

        • 1. Re: Validate field on exit
          Sorbsbuster

          You could attach a script trigger to the field, and have it run OnObjectExit, say (although other trigger conditions would also work).

          The script you attach could be:

          #Check if the Barcode starts correctly
          #
          If Left ( Barcode ; 2) = "+H" Or Left ( Barcode ; 2) = "+M"
             #Barcode is OK
          Else
             #Barcode is not ok
          Show Custom Dialogue ['Invalid Barcode' ; "The Barcode must start with +H or +M"
             #Clear the Barcode field
          Set Field [ Barcode ; "" ]
          #
          End If

          • 2. Re: Validate field on exit
            philmodjunk

            The key is to configure your scanner to put either a tab, enter or return key character at the end of your scanned data. Then set the field behavior so that this key exits the field.

            Then any of these triggers could be used to process the data after it is scanned into the field:

            OnObjectExit
            OnObjectSave
            OnObjectValidate (newly added in fileMaker 11)

            • 3. Re: Validate field on exit
              JamesHalliwell

              Hi Sorbsbuster,

              this is just what i am after many thanks for looking at this and converting the vba to script it is greatly appriciated ,the only thing if you could help is if the barcode is wrong and the user clicks on ok on the messaege box it then to empty and re select the barcode filed instea on moving on to the next field 

              any advise

               

              Many thanks

              • 4. Re: Validate field on exit
                Sorbsbuster

                #Check if the Barcode starts correctly
                #
                If Left ( Barcode ; 2) = "+H" Or Left ( Barcode ; 2) = "+M"
                   #Barcode is OK
                Else
                   #Barcode is not ok
                Show Custom Dialogue ['Invalid Barcode' ; "The Barcode must start with +H or +M.  Rescan?" ; Button Options: OK, Cancel
                   #
                   If (Get (LastMessageChoice ) = 2
                   #Cancel chosen
                   #Clear the Barcode field
                   Set Field [ Barcode ; "" ]
                   Halt Script
                   Else
                   # Rescan chosen
                   Set Field [ Barcode ; "" ]
                   Go To Field ( Barcode )
                #
                   End If
                #
                End If

                • 5. Re: Validate field on exit
                  JamesHalliwell

                  Hi Sorbsbuster,

                   

                  Can i just say thanks for your help on this as im a complete newb to filemaker and you are helping me out big time and i applogise for having to keep coming back, if the barcode begins with +H is working just fine its on the if it doesnt part which i am struggling with

                  If it doesnt begin with +H i get the error but it still moves on to the next field, i think this is because i am scanning into a portal, could this be the cause 

                   

                  many thanks

                  • 6. Re: Validate field on exit
                    Sorbsbuster

                    If the Barcode field was a field in the record you were browsing it would work; I didn't know the field was in a portal.

                    I think you need to confirm which portal row you are scanning into.  Capture that as a $Variable at the start of the scan using the Get (ActivePortalRowNumber) function.  Then make the 'Failed Test' script procedure do:

                    Go To Field [Barcode in the Portal]
                    Go to Portal Row [$PortalRowCapturedEarlier]
                    Go To Field [Barcode in the Portal]

                    (You can achieve the same thing more neatly by naming the Portal, but try this first)