I am continuing my study of the new FileMaker 18 functions. We see this new release as a continuation of the dramatic change in FileMaker as a platform. Todd calls this new release the “End of the Beginning“. Therefore, it’s important to take a look at what’s new and see how game-changing each feature is. It’s just as important, too, to think of when new features will be used. And finally, it’s vital to think of how fast a new feature should be adopted. Let’s study the While Function up close and personal (with all the mistakes and pauses that happens in normal development) and learn more about the FileMaker While function.
Watch me learn
Since I didn’t know much about the While function, I explored it and recorded my exploration. I spend 30 minutes working through the function: reading the help, making mistakes, and occasionally finding success. I’m not sure how others learn and code, but I took my time and played around with things. Many times these new features require some testing and getting things wrong; they’re complex and need some study.
This exploration video is rough; you get to see me without a whole lot of post-production (I don’t even put a title screen on this video). But give it a try. See if it’s useful to you, and feel free to comment on how you code and how you do things the same or differently.
Anyway. Turn down the lights. Grab some popcorn. And explore the
While() function with me.
Some Thoughts about the While function
The FileMaker While function is pretty cool. There’s a lot of new possibility, and with that comes great responsibility. We’re responsible for learning about the
While() function–the structure and how it works–, and we’re responsible for learning when and when not to use it. So let’s write down some thoughts.
- The syntax is very specific and takes some getting used to. I’m using aText to auto-create the function formatted in a way that makes sense.
- You actually don’t have to declare all the variables in the
While()declaration area, but you do have to declare most of them. If the variable is used in the result portion of the function, you must declare it above. Otherwise the function will return an error. You don’t have to declare the variable in the declaration area if the variable is ONLY used in the logic portion.
- It matters where you place the iteration variable. Placing the iterator–in my case
i + 1–before the rest of the logic changes what is returned. I don’t think I have a preference where it goes. I’m choosing to put it after the logic, just like I structure my
Loopstructure in a script.
While()function has ‘block scope’. Roughly put, variables inside the function do not overwrite variables of the same name outside the function. The picture below shows the variable
namewith two values: the yellow
namevariable contains my last
name. It’s outside the
While()function. The variable can be used inside and outside the function, though I’m not sure why anyone would do this, to be honest.
- I unchecked the “Automatically evaluate” box in the calculation dialog. I kept making mistakes, and I’d crash the window. I didn’t want the evaluation to happen while I was getting the syntax correct.
- It’s a bit tough to debug. The logic portion might contain quite complex calculations, and you can’t really test it will. At least none that I’ve figured out yet. I have started to extract that logic and test it in another calculation dialog. Get it working, and then put it back in.
When to use While()
As I was playing with this new function, I was thinking of where it could be used. Like the good ol’
ExecuteSQL() function, this new one could be overused and used too fast. It might be adopted as the new and shiny thing without thought of consequence or consideration. I have no issue with using the function, but I want to stop and consider its use.
We have a bunch of JSON Additions custom functions that use the well-used recursive ability. They work just fine. These functions could be re-written using the FileMaker
While() function, but they already work. So why rewrite them?
Additionality I like to use scripts and subscripts to do a lot of my looping over records or to process records. The
While() function could take the place of many scripts, for sure. But I wonder if I’ll do this. I can easily debug scripts. And I can write modular scripts to work from different contexts, and I am decent at writing scripts.
Using the FileMaker
While() function will take some consideration.
This new function is worthy of study and use in innovative apps. It does solve some problems for us and it does give us an efficient (one-function) way of performing tasks on records or data. As with any new feature the FileMaker
While() function deserves a place in our toolbelt.