5 Replies Latest reply on Dec 8, 2013 8:37 AM by philmodjunk

    Barcode Scanning scripting loop

    Ian

      Title

      Barcode Scanning scripting loop

      Post

           Hello I'm trying to scan barcodes on the same layout as showing the resulting scans as a list, I have placed a Global scan field on the footer of the list layout with a OnObjectKeystroke trigger which triggers with a TAB suffix from the scanner. Everything works fine except till at the end of the script where it points back to the global field to wait for another scan, then it gets into a loop of creating new empty records till I cmd "." to break out of the loop

           I'd like to show the scanned results as a visual check. Could someone please shed some light what I could change / add to stop the looping, some how it self triggers even though nothing is scanned or TAB entered in the Global field.

           Thanks, Ian

            

             
      •           If [ Code ( Get(TriggerKeystroke) ) = 9 ]
      •      
      •           Set Variable [ $Scan; Value:Training::Barcode Global ]
      •      
      •           If [ $Scan = "ENDSCAN" ]
      •      
      •           Exit Script [ ]
      •      
      •           End If
      •      
      •           Clear [ Training::Barcode Global ] [ Select ]
      •      
      •           New Record/Request
      •      
      •           Set Field [ Training::Contact Index; $Scan ]
      •      
      •           Enter Find Mode [ ]
      •      
      •           Set Field [ Training::Scan Date; Get ( CurrentDate ) ]
      •      
      •           Perform Find [ ]
      •      
      •           Sort Records by Field [ Descending; Training::Training Index ]
      •      
      •           Go to Record/Request/Page [ First ]
      •      
      •           End If
      •      
      •           Go to Field [ Training::Barcode Global ]

        • 1. Re: Barcode Scanning scripting loop
          philmodjunk

               Your script does a go to field with every character scanned. Put Go to field before the end if and then you may need to end your script with an exit Script [False] step to cancel out the appended tab character.

          • 2. Re: Barcode Scanning scripting loop
            Ian
                 Thanks Phil,
                 Do you mean every Barcode character? because I thought that the if statement is only true when the TriggerKeyStroke = 9, could you maybe suggest a better way of scripting this?
            • 3. Re: Barcode Scanning scripting loop
              philmodjunk

                   Yes, I mean every character. Your go to field step is outside of the If block and thus the go to field step is executed every time a character is entered into your field.

                   You may find the example scripts used here to be helpful: Need help writing script to integrate barcode scanning

              • 4. Re: Barcode Scanning scripting loop
                Ian

                     The exit Script [False] did the trick, it is strange to me that the script will trigger with no tab entered.

                     Thanks for your help

                • 5. Re: Barcode Scanning scripting loop
                  philmodjunk

                       USB connected scanners almost always function in "keyboard emulation mode". This mode enables the computer to respond to scanner input as though a very, very fast typist entered the data scanned from the bar code. Your script is triggered with every single character input from the scanner, not just the tab key.

                       In your original script:

                       If [ Code ( Get(TriggerKeystroke) ) = 9 ]
                      Set Variable [ $Scan; Value:Training::Barcode Global ]
                           If [ $Scan = "ENDSCAN" ]
                               Exit Script [ ]
                           End If
                           Clear [ Training::Barcode Global ] [ Select ]
                           New Record/Request
                           Set Field [ Training::Contact Index; $Scan ]
                           Enter Find Mode [ ]
                           Set Field [ Training::Scan Date; Get ( CurrentDate ) ]
                           Perform Find [ ]
                           Sort Records by Field [ Descending; Training::Training Index ]
                           Go to Record/Request/Page [ First ]

                       End If
                       Go to Field [ Training::Barcode Global ]

                       The code in blue is only executed when the charcacter entered is a tab character. the text in black is executed with every character scanned off the label and also the appended "tab" suffix.

                       I think the combination of go to field and no exit script [false] step resulted in the script tripping it's own script trigger in an infinite loop due to the fact that this trigger performs a script before FileMaker processes the triggering event (a keystroke). Exit Script [False] breaks that loop by causing FileMaker to not process the triggering event.