AnsweredAssumed Answered

Perform Find 'invisibly' without having to change layouts?

Question asked by smashingly on Jul 27, 2010
Latest reply on Jul 27, 2010 by philmodjunk


Perform Find 'invisibly' without having to change layouts?



I'm trying to do the following, without the layout visibly changing:

On a text field on a layout ("Scanner"), Script Trigger OnObjectSave detects entry of text from a USB passport scanner.  Essentially this is so the user can scan in a passport and it'll search the Personnel database, find a match, grab the foreign key for that Person record and do something with it (add it to a join table).  The script does the following:

Show Custom Dialog [ Message: "I'm going to try and search for passport number " & Configuration::MRP_Passport_number & "..."; Buttons: “OK”, “Cancel” ]

Set Variable [ $passnum; Value:Configuration::MRP_Passport_number ]

Go to Layout [ “Personnel” (Person) ]

Set Error Capture [ On ]

Perform Find [ Specified Find Requests: Find Records; Criteria: Person::Passport Number: “$passnum” ] [ Restore ]

Set Variable [ $errornum; Value:Get(LastError) ]

Set Error Capture [ Off ]

If [ $errornum <> 0 ]

Show Custom Dialog [ Title: "Error"; Message: If ( $errornum = 401; "Passport number " & $passnum & " was not found in the personnel database. Click OK to be returned to the Trip window." ; "Some other error occurred when searching for passport number " & $passnum & ". The error code is " & $errornum & ". Please contact tech support with this error number." ); Buttons: “OK” ]

Exit Script [ ]

End If

If [ Get(FoundCount) > 1 ]

Show Custom Dialog [ Title: "More than one match"; Message: "There is more than one match for passport number " & $passnum & ". Please look through the " & Get(FoundCount) & " matches found and eliminate the duplicates. Then try the operation again."; Buttons: “OK” ]

Exit Script [ ]

End If

Set Variable [ $foundPID; Value:Person::PersonID ]

Set Variable [ $foundFullName; Value:Person::FullName ]

Go to Layout [ original layout ]

Show Custom Dialog [ Message: "Person ID: " & $foundPID & "¶" & "FullName: " & $foundFullName & "¶"; Buttons: “OK” ]   // the end-game will be to do something with the PID but for now, this dialog is all I need for debugging.

So essentially it's running off to another layout, performing a find, getting the PersonID value that matches the passport number scanned, then returning to the original layout.  But it looks as though Filemaker quickly flicks to the Personnel layout to perform the find, then quickly flicks back to the original Scanner Input layout from which this script is run.  Is there any way to use this passport number to locate the person record's PersonID value, without such a visible (albeit very very brief) window change?  Would Freeze Window help here - if so, at what point would I use it in the script?  This is really more about good development practises - the user won't see the window flicker, but if the database was really big, they might do, as the Perform Find would take longer.  If there's a more "correct" way of doing this, I'd rather learn it now in this early(ish) stage in my Filemaker Pro learning!