Developers have been able to “go to”, “set” values and even reference files “By name.” The FileMaker 17 Perform Script By name option is just one of many improvements developers can use to create reusable and dynamic code. The new feature may not change the way we code on a daily basis, but know that it is part of the FileMaker Swiss Army Knife toolbox and how to “flick” it open.
History of “Hard-coded” scripts
Developers have associated their buttons, script-triggers and sub-scripts by hard-coding them to a script for as long asFileMaker Pro Advanced scripts have existed. FileMaker handles the linking of such scripts under-the-hood by ID when hard-coding scripts. This linked behavior is what makes FileMaker applications capable of working even after the name of a script has been changed. The animation demonstrates FileMaker Pro’s ability to keep things intact even after script renaming.
Perform Script by Name History
The concept of performing FileMaker scripts “By name” is not entirely new. Here are a few methods with which this has been done in prior versions.
FMP URL Protocol
A properly constructed URL can be used to run scripts by name. The URL can run a specific script in a FileMaker Pro Advanced file in just about any situation one can open a URL (i.e. within email message, browser’s address bar or webpage, a FileMaker Pro or Go WebViewer).
Custom Web Publishing (API for PHP/XML)
FileMaker’s Custom Web Publishing (CWP) has performed scripts by name since its inception. Developers construct their code in a similar fashion to the FMP URL Protocol example above.
FileMaker 17 Perform Script By list
By default, FileMaker 17 “Perform Script” script step behaves the same way as it did in earlier versions, but looks a little different. When the “Perform Script” script step is added to a script, it defaults to the familiar method of selecting scripts which it now refers to as “From list”. FileMaker 17 displays “Specified: From list” (or “Specified: By name”) and always shows the script parameter placeholder, even when empty.
FileMaker 17 Perform Script By name
The updated script step adds the option referred to as “By name”. A developer specifies the source of the script name by using the FileMaker calculation window. Some written text, a field, a local variable, a global variable or Get ( ScriptParameter ) can contain the name of the script. One could even use JSONGetElement to extract the name of a script to run from a JSON Object. A special syntax ( <FileName>::<ScriptName> ) is required to perform a script “By name” when the script belongs to an external file. The following image shows some examples of these uses.
Perform Script on Server (PSoS) update
Everything mentioned about the “Perform Script” script step is also applicable to the “Perform Script on Server” script step (PSoS). A PSoS script can be specified “By name” or “From list.”
Error 104 Script is missing
Error 104 is not new to version 17 and can occur for several reasons. A script could have been deleted or the value used to perform script “By name” could have a spelling or syntax error. The value could refer to a non-existent script or was simply renamed. Careful planning and error handling are required when using any one of the script steps that “go to” or “set values” by name. Using FileMaker Pro Advanced 17’s perform script “By name” script step is no different. Error 104 will occur when FileMaker Pro Advanced is unable to find a script by the specified name. So be thoughtful when naming and renaming scripts.
The animation in this section’s example uses a button which calls a script by name. Notice how the button successfully calls the script named “Original Name”. After the script is renamed to “Still remember me?”, the button fails. This example contrasts the earlier animation where a button was hard-coded to a script that had been renamed but was automatically “fixed” by FileMaker Pro Advanced.
Here are a few suggestions for using Perform Script By name that have been discussed at Skeleton Key.
- Self-referential Perform Script on Server script steps (PSoS). Some background here at Skeleton Key. We include a little code to conditionally check the environment and platform when we write scripts that could be run via Perform Script on Server. It might save us a little time and gain accuracy by using Get ( ScriptName ) as the PSoS script name to run.
- Loop through a list of script names. Instead of hard-coding several Perform Script steps, it would be possible to work through a list of script names which might be provided in a script parameter, possibly formatted as a JSON object.
- Layout design before scripts. With FileMaker 16 and earlier, when copying layout objects and scripts from one project to another, FileMaker developers paste scripts first, then layout elements. The order is necessary for layout buttons to stay connected to the scripts they run. If your layout buttons use Perform Script By name with FileMaker Pro Advanced 17, layout elements could come before scripts since the name of the script a button is associated to evaluates at the time the button is clicked or script-triggered. This will not likely change our approach to programming in the immediate future for all projects.
For additional ideas and use cases, there is a fairly thorough “product idea” discussion on the FileMaker Community website.
The use of Perform Script “By name” is not an all or nothing situation. That is the beauty of FileMaker Pro Advanced…it gives developers options. Take some time to define your application’s needs and your approach to development. Do you need to call scripts dynamically? Are you willing to give up FileMaker Pro Advanced’s ability to keep track of your script names if/when you rename them? Good luck experimenting and happy FileMaking! Jay Sayers is a FileMaker 16 Certified Developer at Skeleton Key in St. Louis, Mo. This article was also published on Medium.com About Skeleton Key Skeleton Key helps turn complex, complicated, and outdated systems into true information platforms. Our team of consultants and developers do this by developing custom-fit software tools and reporting dashboards that help businesses find, use, and understand their data, freeing them to focus on and grow their core business. In addition to custom databases and applications, we also provide training and coaching for getting the most out of your existing systems and understanding your unruly data. Skeleton Key is an open-book management company and active player of the Great Game of Business.