You don't need to show all records. The script should function the same with that step removed.
Why do you change layouts after performing the find?
Couldn't you go to the desired layout, THEN perform the find? Do you get any difference in the results if you do?
I started with Show All Records as a kind of 'clean slate' start. To make sure I was indeed starting with all records available. Then it seemed logical to perform the find on the layout I was in, take that found set and switch to the layout that would nicely display my found set of records. It seemed logical.
I tried your suggestions: removed Show All Records, moved up Go to layout and and then perform find. Sadly, same result.
Here is a screenshot of the Web browser displaying the initial find where it displays 6 of the 9 records. I just can't seem to figure out why it's showing 4 through 9 of the 9 records instead of 1 through 9?
I didn't have much confidence that altering your script would produce different results, but there can be potential problems with performing a find on one layout, then switching. Both layouts may not be based on the same table occurrence. That is, they might specify the names of different "boxes" from Manage | Database | Relationships in their "Show Records from" drop down lists as found in the layout setup dialog. Each such "box" (called a table occurrence) has it's own found set, current record and sort order so changing layouts can bring up a completely different found set from that produced by your find. Also a change in layouts--if by script--can trip a layout based script trigger that alters the found set by omitting records or some such. My suggestion was intended to rule out those possibilities.
The screen shot shown displays a found set of 9 records but displays the last 6 of those found records. Thus, it appears the find worked, but your web browser is on the 4th record. See what you get if you add a Go to record/request/page [first] step to your script.
Adding Go to record/request/page [first] didn't change the results. But adding that AND removing the sort did work. Now it is displaying all of the records.
If I put the sort back in, the 'error' comes back and I don't see all of my results anymore.
Still works fine in the FMP app itself on the server, it's just the web published page that's not displaying the results correctly.
What happens if you click the book icon to go to the previous record?
To get sorted records, sort the records, then use go to record to go to the first record.