Unsolicited sort occurs

An unsolicited sort occurs in execution of a script. The sort runs over all records of the table and takes several minutes to complete. The progress dialog does not show progress and remains fixed during that period:

The script collects query parameters in variables, then switches to the layout where the find operation is executed and the result is shown:

Sorting shall be done at the end of the script:

Which actually happens:

Why does the first sort occur when no sort step is around?

Client: MacOS, FMP 19.3.1.43
Server: MacOS, FMS 19.3.1.47

I've had this issue also. This is especially problematic with large tables.

Another question: why doesn't FileMaker (by version 19) maintain indexes for user-defined sorts so a sort order change happens nearly instantly?

A very long shot. Is it possible that a step in the script, like the one on line 84, triggers the sort ?

I checked that. There is no sort defined in this context (also not in the graph), apart from that in line 294.
The step in line 84 should not trigger a sort, as there is no predefined predicament that would mandate a re-sort.

A few things to check:
Any layout script triggers?
Has the layout a predefined sort that is set to be maintained?
Any sorts within any relationship links? (I hope not)
Any sorted portals on the layout?

@Torsten When you go that layout, is there a found set that is inherited and that would re-sort ?

Any layout script triggers?
None

Has the layout a predefined sort that is set to be maintained?
None. But the menu Records/Sort Records... yields this:


This appears after the script step Sort Records By Field () executed.

Any sorts within any relationship links? (I hope not)
None

Any sorted portals on the layout?
No portals on layout

What I found is in the reply to @AndyHibbs' post.

In addition to @AndyHibbs's list, ANY calculations in layout objects that reference a field associated with sorted behaviour, such as a summary field. The calcs can be in button labels, hide object when, and conditional formatting.

1 Like

It is a list layout with few objects. There are

  • 3 Buttons, each with the hide condition 'Get(FoundCount) = 0' in header part
  • 1 Button with no hide condition in body part
  • 1 Button in body part (Omit Record)
  • 1 Pop-up in body part (has 3 field objects)
  • 1 Merge field in header part (references a summary field count of records)

Unless I overlooked something, there are no other hide conditions, conditional formatting or other calculations.

I replaced the Sort Records by Field () step by Sort Record ().
The difference is that Sort Records by Field () always keeps records in sorted order. This means that any change of a record's value in the concerned table will trigger a re-sort (also changes performed by other users).
This behaviour of Sort Records by Field () is described in the documentation:

Sort Records () gives control over this parameter:

1 Like

Has that change fixed the problem?

I am still watching it. It does not occur with a single user logged in. And it does not happen each time the script executes.

One possibility comes to mind that hasn't been mentioned yet. When you manually sort there is a checkbox to Keep records in sorted order:
Screen Shot 2021-07-31 at 11.13.06
It is just possible that this is being triggered in some way, perhaps by the change of layout. You could try making sure it is unchecked and see if that helps.

(maybe I didn't see it above) - any luck with moving the FREEZE on a different position within the script?

1 Like

Good point, but this can be excluded because users do not have the ability to call a manual sort in the solution. The trigger for this box being checked was the Sort Records by Field ().

I did not move the Freeze step yet. The scripts task is to open the layout with an empty found set, then freeze until the found has been established. Where would you put the Freeze?

I always put freeze at the beginning of a script to leave all layout redraw attempts alone. would also before navigating to layout enter find mode ..

Then nothing to sort, but since there is something weird going on, did you checked in the script that the found set is empty ?

Adding to @planteg, are you sure you haven’t got a found set from when opening in single user mode? Also, can you enter find mode before navigating to the layout then, make a find that will result in no records, or if appropriate, make the desired find?