I was helping someone debug a script that did not seem to be working. After much debugging, we finally identified that a Sort records script step wasn't working.
The table was almost (but not quite) sorted to begin with, so it looked like it was working poorly, when in fact it just wasn't working at all.
After a bunch more head-scratching, including looking for Unicode sort order issues, searching for invisible characters in fields, etc, we finally figured out the problem - this Sort step was running in Table A, but the Sort criteria were using fields from Table B.
Both table A and B have identically named fields, which made it less obvious.
Important note: Table A and B are not related, the fields are not Globals.
Why does FileMaker allow this?
- At design time: The script editor doesn't know what context a step will occur in, so it's somewhat sensible that it can't prevent that mistake during script design.
- At runtime: However, when the script step runs, the runtime absolutely knows that you can't sort Table A on fields from Table B, and it should throw up a runtime error. The fact that this isn't considered an error seems like an "interesting" choice, if not an outright bug.