Script debugging has received an overhaul in FileMaker 9. FileMaker 8 launched a great feature with the data viewer but FileMaker 9 has made it an indispensable tool. Not to be outdone, the debugger also received some updates that make it a much more powerful tool. All in all, I’m sure you will be happy with your new debugging tools.
Disclaimer: The following applies to FileMaker 9 Advanced users only
## Debugging with Different Users ##
In previous versions of FileMaker, you could never quite tell how a script would react for users with different privilege sets. This problem occurred mainly because the script debugger could only be accessed when logged in with an account that has ‘[Full Access]’ privileges. FileMaker 9 provides a solution for this problem.
When you open the FileMaker 9 debugger you’ll notice it just pops up in its own window. In previous versions of FileMaker, the debugger would only be displayed during script execution. Besides all the icon changes, you’ll notice a little lock in the upper right hand corner which is where this gets interesting.
> Tip: FileMaker has made the Script Debugger available *even* when executing a script. So if the debugger isn’t open, you can actually select `Tools -> Script Debugger` in the middle of executing a script and it will just pop open. This comes in really handy when you are in a dreaded infinite loop because you can just hit red x and halt the script. Or if you just want to pause your script, you can hit the little battery icon and add a breakpoint. Viola, your script is paused.
Let’s say you favorite user “Joe Always Complains About Stuff Not Working”, who was hated by his parents hence the really long name, complains to you hey Script X doesn’t work correctly. You know he’s probably going crazy, but since you’re a nice guy you go through your typical steps of debugging to ensure that your script is indeed as immaculate as you thought it was. Well, you don’t find anything wrong so you have to try to go and see how it reacts for him. To do this you just go ahead and log in to FileMaker as Joe Blow (or if for some strange reason he has advanced on his computer just do it there) then open your debugger and click the little lock. Now all you have to do is login using your `[Full Access]` account and your home free. The script now reacts the way it would for Joe.
> Note: To ensure that this executes exactly as Joe would see it I change my user name preference in FileMaker so that it matches exactly what Joe has on his computer. This setting is under FileMaker Pro Advanced -> Preferences and is easily changed by entering Joe’s system name into the user name field.
## Last Error ##
Another great feature that is added to the debugger is that it has a little display for the error code that occurred during the last script step. I can now remove the permanent resident `Get( LastError )` from my data viewer. If you click on the error code, help will pop up with FileMaker’s standard definition for the error. A helpful with the error code, FileMaker 9 has added a little check box to stop the script when an error occurs. I can definitely see using this in the future but really isn’t that world altering to me.
## Clicking Edit while in a Script ##
There is one final minor upgrade to the debugger. If you click the edit button while executing a script, FileMaker now opens ScriptMaker, opens the script you were debugging and goes to the exact script step that you were about to execute. Definite time saver.
## Data Viewer – Current Tab ##
A tab called `Current` has been added to the the I can’t think of how many times I have painstakingly in all my scripts variables or added a field to my data viewer. With the Current Tab all this is done for you! Every time you run a script, every variables and fields that your script accesses is displayed automatically for your easy consumption. This had definitely taken away a lot of the overhead setting up the different values you wanted to follow.
> Note: Don’t worry though, they still allow you to switch to the `Watch` tab and keep track of whatever field/variable/calculation you can dream up.
Whenever a script isn’t running the current tab still provides a very useful service. It allows you to see see all the global variables that are defined for whichever file you are in. Another truly wonderful trick. Trying to track down variables that are misspelt or just plain not used just got a lot easier.
## Data Viewer – Editing Variables
After getting over my euphoria of the `Current` tab and with a little nudge from the venerable Andrew LeCates, I noticed another data viewer gem. The new data viewer allows you to edit variables. All you have to do is pop open the data viewer, double-click on the variable you want to edit and you should see this guy:
Now all you just type in whatever your heart desires into the dialog and hit ok. The next time you have a loop based on a counter variable you no longer have to cringe at debugging it. Just set the variable to whatever you want and watch it zip along.
There’s a bit more to the Current tab of the Data Viewer. Try double clicking any variable shown in the list, and you’ll find you can directly edit its value – and handy time saver while debugging.
@andrew: Thanks for the tip. Jesse showed me this just the other day. I never thought to try.
@Andrew: Thanks Andrew, I think that is probably my second favorite new addition. I keep forgetting to update this article. Another nice tip is that when the data viewer is open and you aren’t in a script you can see your global variables. I am going to make the edits and add some screen shots today so come back later and tell me what you think.