In this series, “Use FileMaker Like A Boss“, we’re exploring those techniques, mindsets, and tools that make us a better developer. I’m starting the series with topics based on my own discoveries during my FileMaker formative years. In this post, we will take a look at the FileMaker Data Viewer.
As a developer who stumbled into FileMaker, I always had a copy of FileMaker Pro Advanced, but the tools that were included largely went unused. The data viewer, when I finally found it, proved to be something that I can’t live without. The amount of information presented there was amazing. As I look back, I’m surprised I could do anything in FileMaker without the data viewer.
The FileMaker Data Viewer Up Close
The FileMaker Data Viewer has quite a bit of functionality packed into the small window. It is a place to view values of variables and fields and expressions. When I need to test a function out or work on my ExecuteSQL() syntax, I use the data viewer. I’d hazard to say it’s the most commonly used window in our tools. It certainly is for me.
There are two tabs: Current and Watch. The current tab, as it says right there, shows the variables and fields being used in the current script. Seems simple enough, but there’s a lot of power in this statement. We’ll get into those in a bit.
The Watch tab is a place to “Monitor the values of fields, variables and expressions.” Again, simple on the surface, but this space allows for some great complex work.
What’s happening now
The Current tab shows the value of all fields and declared variables in the current script. Here you can see all the fields that you need for this script and their value if applicable. Such usefulness!
FileMaker Data Viewer Facts
There’s much going on in the Current tab:
- Fields that are not part of the current context of the script (the underlying Table Occurrence of the current layout) have a value of “<Unrelated Table>”. That’s okay.
- If you’re using the script step Set Field by Name, you will not see that field in the list.
- The default sort is the Names column, but you can sort by others as needed.
- Variables are included as they’re declared, so these may be out of order until you specifically click on the Names column.
- Fields are always at the top, and variables are sorted to the bottom with global variables above local variables.
- A field or a variable can be added to the Watch tab via the button with that name. We’ll take a look at this in a bit.
- Global variables are shown here as well.
More About Variables
Variables are shown in the Current tab, whether they are the local kind ($var is available only for the current script) or the global kind ($$var is available for the entire file). These are listed below the fields in the data viewer sort order. A variable gets added to the Current Tab only after a script step in the current script declares it. If the script debugger enters a subscript, the local variables for the parent script are no longer available. They will disappear from the data viewer list until the debugger returns to the parent script. This is important. If I declare $Id in the parent script, it is NOT automatically available to a subscript. It would be available if I passed its value to the subscript and then re-declared it there.
Why the FileMaker Data Viewer is Useful
Many developers set their scripts up to perform actions on a blank layout. This layout contains no fields or objects save maybe a “Processing this record.” piece of text. Since there are no fields on this layout, so I need to use the data viewer to view the fields and their values. If, for example, I create a new record on a blank layout, after each Set Field  script step, I want to make sure the fields in the underlying table are getting filled as I would expect. I don’t have to look at the layout itself. Instead, I keep my eye on the Data Viewer Current tab.
Another useful feature is the ability to change the value of a variable, be it a local one (as the script is running) or a global one (any time). Let’s say the script declares $y to have a value of 275. That’s nice, but as I debug, I want to test another value. So, after it has been declared, I can click on the variable in the data viewer and change its value. After clicking “OK”, the value gets saved back to the variable, and that value will be used in the rest of the script.
Final Thoughts About the Current Tab
- Fields are automatically sorted since they all begin with their table name.
- Variables are also sorted by name by type. However, in a long list of fields and variables, it can get tricky to find a certain variable. So adopt a naming convention that will put like variables next to each other, something like $idProperty and $idCorporation, etc. Some folks use dot notation: $id.Property and $id.Corporation.
The Watch Tab
This tab is probably the most used by FileMaker developers.
There’s a lot one can do here. You can:
- View developer-friendly data about the file (#1 in the picture above).
- Test out a function or a long calculation there (#2 in the picture above)
- Watch specific field or variable values in the currently-running script (#3 in in the picture above)
- Add variables and values that effect the logic of the script
- Change variable values that result in the logic of the script changing
Let’s examine each one in turn.
Test out a function
As I work to develop a script or calculated field, I can test out what I think will be the syntax in the data viewer’s Watch tab. I can add a new calculation with the + button and work away. If I’m in the correct context, if I’m on a layout that contains the table and the fields I am working with, those fields and related ones) are available to the data viewer. So I can work something out.
Watch a specific field or value values
As a script runs, the data viewer Current tab fills up with fields and variables. I can move one ore more of them over to the Watch tab and hold them there to view them separately. Once a field or variable is in the watch tab, it will stay there until you remove it (or FileMaker crashes).
I can even add a variable to this tab and use it in the currently-running script. Here’s a scenario: A script is supposed to pick up an optional script parameter with the value of “Contacts”. However, I run the script from the Script Workspace. The $param variable doesn’t get the script parameter, so I can manually set it:
Let ( $param = “Contacts”; 1 )
This variable will remain “Contacts” throughout the script, just as I need it to. The 1 in this calculated section allows the Let function to work correctly. It is only the variable’s value I care about.
Change a Variable’s Value
Similar to adding a variable, I can change the value of the variable in the calling script. This is a bit tricky, but it does work. Here’s how: As a script runs, the script sets the value of $param to “Students” which came from the button’s optional script parameter. But I want to test the logic of the “Contacts” section, so I can use the above function to change the $param from “Students” to “Contacts”. As long as I press the button “Refresh Values” this value will override what was initially set in the script.
Be careful with this. What you have set here will override the script’s declaration even if you didn’t intend for it to happen. It is best to use this feature sparingly and to remove the variable as soon as possible. This issue also happens when you declare a variable, as described above. So be careful!
A final few words about the Watch Tab
- The Watch Tab’s values are lost when FileMaker has a hard crash. The tab will be blank when reopening FileMaker.
- The watch tab is not file specific, so you’ll see many fields or functions that have nothing to do with what you’re working on right now. As long as you don’t mind it, keep them. Like a sock drawer or closet, it is always good to clear them out one in awhile.
The FileMaker Data Viewer is essential to a developer’s process. I can’t recall the last time I didn’t have it open. I’ve grown in my use of this tool in the past few years. I strongly recommend you take time and explore all it has to offer.