I played around with it a little more using a new, blank layout and it works. This makes me think that there may be a script trigger on the layout that is getting run between the Perform Find command and the Set Variable command. That still feels like a bug to me.
One way to see if a trigger performed script is interrupting a given script is to use FileMaker Adavanced's debugger to run the script one step at a time. If a trigger for a script is tripped, you'll see that script pause the current script and then your debugger starts stepping through the trigger controlled script.
are all triggers that the above script might trip before or after the find is performed.
But I do agree that this appears to be a bug.
I set up a script: Show Custom Dialog [Get ( ScriptParameter ) ]
And then setup the above triggers on a layout with different parameter expressions for each trigger.
I then ran the same script shown here with criteria specified that I knew would fail to find any records.
I saw multiple dialogs pop up due to the script triggers being repeatedly tripped by this script, but no error code is shown in the final custom dialog.
If I then remove the triggers from Layout setup, I get an Error code of 401 in the custom dialog as expected.
If the Perform Find step is performed on a layout where the triggers indicated by Phil are installed, you may would to capture the error within a Set Variable [$$error] step, as the first command of an OnModeExit triggered script, with the Search Mode activated on the trigger.
Because you are able to capture the 401 error since exiting the search mode.
However, i do not think the Set Error Capture [Off] when starting the main script is truly relevant here.
i do not think the Set Error Capture [Off] when starting the main script is truly relevant here.
The main concern is that an error code generated in a script should not be wiped out by a different script that interrupts the first script. Just as a local variable, $Variable, should store data specific to the script in which it was created, so Get ( LastError ) should function from the data scope of the script where it was placed instead of behaving as though the trigger performed scripts were magically inserted into the middle of the script that tripped their triggers.