Local $variable inside a Single Step button calculation

I think I've found a bug in Replace Field Contents where there's a difference between a Button that runs a script vs. a button that has a single script step.

I'd like another pair of eyes on it.

The goal is to take the current found set, and make a list of the record serial numbers, using this calculation:

What this does:

  • for each record in the found set
  • add the field named "ID" to the list stored in $L
  • if the record number = the found count, then we are done and can store the result in the global field

When this is part of a Script, it works normally - the list has 192 values, and the calculated field automatically updates and show a count of 192 values.
You can click the button repeatedly and it always gives you the same list of 192 values as expected.

However, when this RFC is run from a button which has a single step...

  • the first time you run it, the values are correct (192 values). However, the ListCount field does not update (so you need to click the "Refresh" button)
  • thereafter, each time you click the Button, the list of values increases in size by 192:
  • closing and re-opening the file resets the behavior, so it starts again at 192, then increases in size each time.


  • I'm seeing this in FileMaker Pro 18 through 20 on macOS running locally. I have not tried it in FMS yet.

Here's the sample file:
RFCbug-v1.fmp12.zip (248.4 KB)

Great observation. I think it is correct behavior since the scope of your $L local var is within the script (which clears out when the script terminates) in one case and in the other within the layout of the button since the single step button "script step" is not a script. Hope I explained well ..


BTW you could fix it and make it work as desired in the button by adding another case/if to your let statement: Let ( $L = if ( get ( RecordNumber ) = 1 ; Table::ID ; List ( ... ) ; ... )

1 Like

I think you are correct, but it's even weirder. The $L variable is not only persistent on the layout, it also keeps its value on other layouts and TOs as well.

So the real issue appears to be something more general:

  • a local $Variable set in a Button that executes a Single Step, the $Variable will be available to all Single Step buttons across the entire database.

I'm sure I don't like it. Is it a bug? Hmm..

since it isn't properly documented at least AFAIK it might get out of control to grasp entire behavior in every foreseeable contexts and it might slightly alter its behavior on revised versions.

1 Like

This is old news. $variables are designed to be scoped to a script. Their behaviour outside of scripts is undocumented, poorly understood and discouraged.

1 Like

Where I am with @xochi is that a one script step button appears to some as a mini script and therefor somehow expected behavior to be consistent..

1 Like