5 Replies Latest reply on Oct 21, 2010 11:28 AM by philmodjunk

    Script to perform find in one field then automatically insert date in another field

    VictorVoegtli

      Title

      Script to perform find in one field then automatically insert date in another field

      Post

      I have an inventory database where when I check things in I want to perform a search on the item's barcode (using a barcode reader). If the item is found I'd like it to automatically place today's date in the Returned Date field. After the date is added I want the form to reset in order to take the next item. If the item is not found I want an error message that reads something like "Item not found".

      Their are really only two fields: Barcode and Returned Date

      I am a novice at scripting but have written a couple very simple ones. So I am confused about how the easiest way to accomplish this. Any advice would be appreciated.

        • 1. Re: Script to perform find in one field then automatically insert date in another field
          philmodjunk

          Are you using FileMaker 10 or 11? If so you can use script triggers to automate the barcode scanning process.

          Make the field where you are scanning in the barcode a global text field. I'll call it, gScanText.

          Enter Find Mode[]
          Set Field [YourTableName::Barcode  YourTableName::gScanText]
          Set Error Capture [on]
          Perform Find []
          If [Get (FoundCount ) > 0]
             Set Field [YourTableName::Returned Date ; Get ( CurrentDate ) ]
             Set Field [YourTableName::gScanText ; "" ]
          Else
             Show Custom Dialog ["Item not found...]
          End IF

          • 2. Re: Script to perform find in one field then automatically insert date in another field
            VictorVoegtli

            Thanks Phil. This really helps me out. Yes - I am using FM10. 

            One thing : how do I get it the script to reset the form to accept the search for the next barcode?

            • 3. Re: Script to perform find in one field then automatically insert date in another field
              philmodjunk

              That's what this step in the above script does:

              Set Field [YourTableName::gScanText ; "" ]

              • 4. Re: Script to perform find in one field then automatically insert date in another field
                VictorVoegtli

                Hi Phil,

                I'm still have problems executing this script.  Here are a few questions:

                1.  Is there supposed to be a semicolon separating the two field in the second line of your original code? To indicate  the target field and then  calculated result?   

                 Set Field [YourTableName::Barcode ; YourTableName::gScanText]

                2. When I created the global text field did I have to set another other parameters for it, such as validation?

                lastly,

                3. Do I have to set the script triggers on gScanText? like OnObjectEnter, OnObjectKeystroke etc...

                • 5. Re: Script to perform find in one field then automatically insert date in another field
                  philmodjunk

                  1) Muy Bad on the typo, there should be a semi-colon there

                  2) no validation would seem to be needed for this field since your scanner is entering the text not via keyboard. If you do need to type in the code manually from time to time, then you may want to set up some validation for this to help catch typos.

                  Here's how you can use script triggers.

                  Almost all scanners can be set to put one or more characters at the beginning of the text actually scanned in from the barcode. This is sometimes called a "pre-amble". They usually can also be set to put one or more characters at the end of the scanned text and this might be called a "post-amble". You'll need to research your user manual and maybe even contact tech support for the scanner to find out how and what options you have.

                  On the layout, you can set an On Keystroke script trigger that runs a script like this:

                  If [get (TriggerKeystroke) = "~"]  
                     Go To Field [YourTable::gScanText]
                     Exit Script [False]
                  End If

                  If your scanner lets you include Shift and/or caps lock key, You might include a check for them in the if step using Get (TriggerModifierKeys) to get a key combination such as shift-capslock-~ that is even less likely to be pressed by accident.

                  You can also include the first script I posted here inside an If step that checks for a Post-Amble keystroke or you may be able to program the scanner to append a Return, Tab or Enter key character to the end. If you can do that, you can use a separate On ObjectExit trigger to run the first script. This is a nice approach if you can set it up as it will also support manually entering a code and pressing one of those keys to exit the field.