JavaScript Functions in FileMaker

JavaScript Functions for Speed and Profit

The movie below is from one of our most popular demos from “Year in Review” at DevCon 2014. I was talking about what a breakthrough custom functions were back in 2004 and how they unlocked a whole new kind of code-sharing among FileMaker developers. JavaScript functions in FileMaker may unlock even more potential.

Jason Young introduced the idea of using JavaScript as a calculator–as a library of functions–instead of using it for perhaps the more obvious purpose of building interface elements. (Jason’s original article on this can be seen as part 1 of this post.) This gives us a huge opportunity to share and borrow code from the immense catalogue of JavaScript functions and examples.

FileMaker Custom Functions Forum
FileMaker engineers start posting custom functions to a public forum: March 2004

As just one example, we (Jason) rewrote the venerable “namwoB” function in JavaScript. namwoB was the first recursive functions I ever saw and was posted by Andy LeCates back in March of 2004. The title comes from Court Bowman’s name spelled backwards… which is all the functions does, rewriting a string of text in reverse. This simplicity makes it a great way to talk about the different kinds of recursion in FileMaker and what a faster version of the function might look like in JavaScript.

Our example file shows the same recursive custom functions done as a “stack” recursive function (limited to about 10k loops), as a “tail” recursive function (limited to 49,999 loops), and as a JavaScript function executed in a webviewer and then passed into a FileMaker script.

Download the example file

JavaScript Functions in FileMaker are Fast

Looping through 49,000 characters took our tail-recursive custom function almost 3 seconds.

The JavaScript version of the function looped through 10 times that much text–nearly 500,000 characters–in 3/10ths of a second.

And thanks to the improved fmp url in FileMaker 13, we can grab the results of functions like these quite easily. The movie below demos this and walks through our example file. It also gives a nice side-effect-demo of how webviewers get their own thread in FileMaker Pro and what that may mean for trying to measure performance.

Featured Posts

Follow Along

Stay up to date with the latest news & examples from SeedCode

11 Comments

  • David

    Hi I am trying to learn this technique but some how it is not working for me. I have tried sample file in FileMaker 13 and it crashes. In FileMaker 14 and 15 my Mac swaps memory as crazy and the system becomes unresponsive. I am using El Capitan. Could it be that Webkit is leaking memory? Any help will be appreciated. Thank you

    • seedcode

      Hi David, It requires 13.0v3 or higher so that may be the issue in 13. You can also probably get past the speed in 14 and 15 by using < 49K characters in the JS example. Start with a few hundred characters and you can still see how it works. (On my FM15 machine it hung the first time I opened it and tried 49K characters, after closing and re-opening FM15 it seems fine and does 49,999 characters in 0.39 seconds.)

  • Richard

    This is excellent. Maybe this will encourage Filemaker Inc. to include Javascript natively in Filemaker in some future version.

    • Jason Young

      +1!!

      • Andy Frazier

        Oh, yeah…a native ExecuteJS() function gets my vote!!

  • Thanks for posting this demo and making a video, John (and Jason). I appreciate how much time it takes to develop new techniques like this and then find the time to properly share them on the web. I’m sure the rest of the FM community likes it, too!

  • Great stuff, as ever, John! It’s really wonderful to see the FileMaker community getting excited about the huge potential of JavaScript.

    On our end, we’ve been busy cooking up some new techniques we’ll be sharing soon as well. Looking forward to trading our best ideas and exploring new uses of JavaScript together as a community!

    • seedcode

      Luv your stuff, Brian!

  • Thanks John. This is very cool and it makes me wonder about using Javascript to parse FMP fields using regular expressions, which is not easily done natively in FMP.

Leave a Reply

Your email address will not be published. Required fields are marked *

Check out some of our other posts ...

New Week Views in DayBack for FileMaker

You can now expand DayBack’s week views to show two or three weeks at a time. We’ve been using this internally in beta mode for a few weeks, and it’s very helpful to see what’s coming up next week while navigating this week’s work. Find tips on how to work with these new views on the DayBack blog.

To-Do Lists in FileMaker – New in DayBack Calendar

Now create and manage FileMaker to-do lists directly from the Unscheduled Items sidebar in DayBack Calendar. Our latest extension brings to-do behavior to any FileMaker table. Like unscheduled items, this behavior is based on a new checkbox field in your table, so some or all of your records in the table can be treated as to-dos. Mark your to-do’s done as you complete them, or drag them into the calendar to schedule time to work on them. See it in action here: Customize Your To-Do Lists This extension was designed to be pretty a scaffold onto which you could build your own, more specific to-do behaviors by customizing the action itself or the FileMaker scripts tha manipulate events. Here are some ideas to get you started. Add To-Do Lists to Your FileMaker Calendar If you haven’t already enabled the unscheduled sidebar along DayBack’s right edge, you can learn how to turn that on here: unscheduled items in DayBack. Then, download the custom action and learn how to configure it here: To-Do Lists in DayBack Calendar.

Improved Resource Selection

We’ve made some big changes to how you filter and assign resources when editing events in DayBack. These changes will make it much easier to work with large numbers of resources, especially for folks assigning multiple resources to the same event. Watch a video of the new behaviors and learn more here: Adding Multiple Resources to an Item. If you haven’t looked at your resource field mapping in a while, here is how you set that up: Mapping the Resource Field in FileMaker. Please get in touch if you have any questions about this; we’re here to help.

Suggesting Appointment Slots

Show Available Slots that Match Multiple Criteria Schedulers often look for gaps in their schedules to find the open resources for each opportunity. But sometimes, gaps don’t tell the whole story. You may have invisible criteria like skill-matching, cleaning requirements, or multiple resources to schedule at once. Or you may be on the phone with an opportunity and must suggest available times as quickly as possible. In these cases, DayBack can suggest the best slots that match all of your requirements. Scheduling Criteria Are Often Invisible In the movie above, schedulers can see openings for the two technicians, but they can’t easily see if the required rooms and equipment are free at the same time. While DayBack can show different types of resources simultaneously, as the number of criteria increases, it can be hard for schedulers to see everything at once and still make good decisions. Our customers often have rules that constrain when an otherwise open slot can be scheduled. Here are some of the invisible criteria we’ve built out for customers: Because DayBack is highly scriptable, it can scrub open slots against a variety of criteria to render just the slots that fit all your requirements. When multiple slots match, DayBack can even rank them so you can present the most ideal slots to your clients first. You Have to *See* Slots in Context to Make the Best Decisions Many scheduling apps present possible appointments as a list of dates and times. Without showing more information about each slot, schedulers can book days too tightly, always suggest the same providers first, or create huge gaps in some provider’s schedules. Ranking slots can help, but we’ve found that highlighting ideal slots alongside existing appointments gives schedulers the information they need to make the best decisions. We’ve seen schedulers quickly offer to split appointments or to slightly change services when they see available slots in the context of other appointments, trainings, vacations, and breaks. Getting Started We customize the recommendation of slots for each deployment as part of DayBack’s implementation packages. Please get in touch if you think DayBack could make a big impact on your team.

COMPANY

FOLLOW ALONG

Stay up to date with the latest news & examples from SeedCode

© 2024 SeedCode, Inc.