Filemaker Error 401

No this is not an AP class on FileMaker Errors. FileMaker Error 401 refers to the dreaded, script killing, FileMaker Error 401. Many of us have encountered an annoying pop-up stating “No records match this set of find requests” in the middle of our carefully crafted scripts and don’t really know where it comes from. The error message FileMaker’s way of saying that your script just performed a find, and it couldn’t find any records. But in practice, you often don’t want to tell your _users_ no records were found. Instead, you just want you script to note this fact, adjust its behavior accordingly, and keep on trucking. More often than not, when this error message pops up, the poor user can’t figure out what to do: “Should I Cancel? or should I Modify Find?” Perhaps he just pounds the escape key until something happens. All three choices seem like perfectly rational responses to me, but are probably not what the programmer intended.

This whole problem occurs because whenever any kind of error happens in a script, FileMaker temporarily stops the script and reports the problem to the user, who is usually ill prepared to do anything about it. This article shows how to catch this error and make sure that your scripts continue to run smoothly.

The easiest way to get ride of this (or any other) error message in your script is by using FileMaker’s `Set Error Capture` script step. When you turn error capture on in your script, FileMaker stops telling your users about errors. That may sound like a perfect solution, but it’s only half the battle. Your script may also need to check to see if no records were found. (Of course it may not care if no records were found, and just want to continue on.)

If it does care, though, it isn’t that difficult to fix either. Even though Error Capture prevents the error _dialog box_ from appearing to your user, it doesn’t suppress the error entirely. Instead, FileMaker notes the error, and tucks it away in case you script cares to look. FileMaker has a calculation function that allows you to get the error code that occurred when the previous script step was executed. This function is conveniently named `Get ( LastError )`. Most of the time this function will return a value of 0 (meaning no error occurred), but when no records are found it returns 401 instead. If we want the script to react differently, we are going to have to catch this error so that we can inspect it later.

Luckily, FileMaker 8.0+ has variables which make capturing temporary data like this very easy. Unfortunately, we are going to have to slide our variable in between the `Perform Find` and the `Set Error Capture – Off` script steps. Once we have the Set Variable script step directly after the `Perform Find`, just pick a variable name… I like $error…. and set the variable to the function `Get ( LastError )`. Voila! The error code for the find request is stored in our variable which I will now refer to as `$error`.

The final part of this problem is to check and see what is in the variable `$error`. In the ideal case, we will get `$error = 0` and everything moves on as if nothing happened. The case that we are looking for is when `$error = 401`. When `$error = 401` we can do any number of things including call another script, show our own dialog or even just exit the script. To check for these two cases all we need is the `If` script step. I like to say:

If[ $error = 0 ]…. continue the script
else…. do something different

This statement not only catches the 401 error but also catches all the other weird errors that FileMaker can throw when doing a find. Now you’re done! You can go on about your merry way and never have to worry about that annoying pop-up disrupting your work flow.

If you find that you end up using this technique a lot, with a couple additional steps you can make a script out of this process. First, copy everything from `Set Error Capture – On` to `Set Error Capture – Off` into a it’s own brand new script. Second, add the the `Exit Script` step to the end of the script. Third, click specify on the `Exit Script `step and place the variable that I call `$error` in the calculation screen. Now you have your own self contained error dialog free find! You can just replace all your old `Perform Find` steps with this new script and you won’t ever see a stupid `No records found` message again. If you still want your script to react differently when you get an error, all you have to do is check the custom function `Get ( ScriptResult )` and you will be able to see the error code for the find.

Leave a Comment

1 thought on “Filemaker Error 401

  1. thanks for this – I was having a hard time with errors crashing IWP & this helped me figure out the problem.