Writing Custom Functions - Successfully

While taking the time to write a four hour custom function the other day, it occurred to me that some viewers may think that complex custom functions are just something which pops out of your head and immediately ends up on the screen.

When, in fact, the truth is it takes a lot longer than you expect because you rarely get things perfectly the first time. It's all about wading through the errors and issues and ending up with the desired result.

In this video, I walk through my process of composing Custom Functions and talk about every detail I can think of. Many of the tips and tricks will also be applicable to your normal process of composing calculations. There are a few nuances which are specific to composing Custom Functions and it's well worth the watch if you're dealing with any kind of JSON based data. If you've always wanted to improve your confidence related to composing code for calculations, then I'm sure you'll gain a good bit of insight when watching this video.

AttachmentSize
WritingCustomFunctions.zip69.81 KB

Comments

Is there a chance you have put effort into coming up with a trick to address an issue that does not exist? ;-)
I have not found any issue with using JSONSetElement within the While function, but I did find an issue with the scope of variables within the While function.
The issue is that if a local variable is first defined in the "do" section but it's not defined (set) in the "init" section then it's discarded in the end of each iteration.
Try to compare results of these two calcs:
Let ( x = 5 ; While ( [ i = 1 ] ; i < 5 ; [ x = x + 1 ; i = i + 1 ] ; x ) )
Let ( x = 5 ; While ( [ i = 1 ; x = x ] ; i < 5 ; [ x = x + 1 ; i = i + 1 ] ; x ) )

Hey HOnza, Thanks! That's something I didn't know about. I was unaware that the variables in the iteration section did not persist unless declared within the initialization section. Although, that now makes sense. I just didn't put the two together before now.

For anyone who reads these comments, you'll find that you don't have to use the $local_variable. However, I'd like to stand by the knowledge that this is a possible solution that does become useful in some cases where you are potentially needing a creative solution to something. It's also nice to know that you can use the JSONSetElement just for the purpose of it providing the functionality of escaping data.

Much thanks to HOnza for pointing this out!

-- Matt Petrowsky - ISO FileMaker Magazine Editor