Problematic Field Names

I just discovered something totally unexpected this week and I absolutely wanted to share it.

I worked in a customer's solution this week and saw a weird script step.

script step

I asked myself: What kind of variable name is this? Then I noticed this was a field reference, so asked myself: Since when can we substitute a table name with a variable? I was puzzled. Then someone noticed there was a base table and table occurrence name called A&B… and it sunk in.

We've all seen this message right?

FileMaker deals with problematic table and field names by wrapping them this way: ${problematic_field_name}.

FileMaker says "cannot be easily used". This implied there could be limitations. I had a bit of fun. I created a small table in a test file with problematic field names and calculation fields.

I put the fields on a layout and added merge fields too – because why not?

And then came browse mode. (BTW: I noticed the merge field says ${B&N. I took this image before I changed the table name to A&B.)

browse mode

FileMaker also automatically wraps the table and field names when you double-click them in a calculation or formula (in a field definition, in the data viewer, in a script, etc.) I would need to embed a video to show you and… well… I didn't feel like making one. (Sorry! I am somewhat lazy.)

It mostly works as you can see. I tried to coax the get (foundcount) field to behave in the merge field but, alas, it was in vain.

This was all for fun. Seriously… don't do this at home, we're professionals. While it is nice to see that FileMaker does its best to handle newbie or non-programmer mistakes, we-who-know-better should stick to good naming practices.

What I don't get, though, is where on earth is the documentation for this? I mean… I could have saved all this trouble and avoided all this fun!

5 Likes

I remember some years I went across this. Not sure but I think it was in a tool that is use to analyse a file. It's in the documentation, but finding it is complicated.

1 Like

I like the examples you created, especially Get( FoundCount ) as a field name! :smiley:

One interesting nuance is that the escaping seems to really only be applied when absolutely needed. That is, FMP doesn't seem to apply the escaping as a blanket rule across all field names that happen to match a reserved word or function name. Generalizing what I have observed, it would be that it only applies the escaping when context within a calculation could be ambiguous. To be more concrete: Cases where a field name matches a FMP function name only trigger the escaping if the function can be used without arguments (hence the ambiguity).

As examples:

Fields named: Date, Length, Time, and CurrentDate will not wind up escaped, because context allows for differentiating such fields from a function of the same name.

In contrast, field names such as: Bold, DatabaseNames, and Pi will wind up with escaping.

(Similar for table names)

As I type this up, I am starting to recall the first time I saw this. It was in the personal solution of a friend who used all kinds of not recommended names for fields. It comes back to me that I was totally scratching my head at this odd syntax that I had never before encountered...

1 Like

Yes… if you double-click a field name. You can type the escape sequence for any table or field name, even if not necessary, and it will work.

2 Likes

Ah. I see, and of course. It never much occurred to me to try to manually create the escape sequence, but it makes sense that it would be upheld, regardless of whether necessary or not.

Here is the page in the documentation that explains the escaping method in FMP 19:

Using a reserved word or symbol for a field or table name | Claris Pro and FileMaker Pro Help

The same page in help for FMP/FMPA 16:

Using a reserved word or symbol for a field or table name (filemaker.com)

How did I found this ? Not by searching in the Help File, but googling filemaker escaping field name . When looking for something in the Help File, googling is your best friend. FileMaker Help, like many other Help Files find what you need, when you know what you are looking for. Google index everything in Web pages !

FileMaker is so forgiving that it escapes those reserved words, well not always, buts most of the time. Thank you FileMaker.

3 Likes

You can also run into this escaping method on old FM code, opened in current FM, where the command has been changed, or in rare instances, deprecated. I don't have any current examples, but I have run into this often with legacy code.

Some interesting insights in this thread; thanks for posting it bdbd.
As it happens, I came across this FM behaviour just last year, when I undertook to update some early (.fp5) files for a client, and found they were full of this escapology. And thanks for the Help links and search tips, planteg.

1 Like