Skip links

Structure FileMaker scripts with comments in ScriptMaker.

FileMaker training, courses, coaching

Structuring FileMaker scripts with commentsThis article is not an introduction to FileMaker scripts. Rather, it is about the necessity of comments in FileMaker scripts. Those who use FileMaker scripts only rudimentarily can possibly do without comments, but those who create entire applications in FileMaker would do well to stick to a standardized system for commenting the function in general and the script sections in particular. Complex scripts consist of many script commands. Often, additional sub-scripts (functions) are executed, parameters are passed or received, loops are run through and variables are used. In order to maintain an overview in this structure of dependencies, it is absolutely necessary to comment the steps. As it can happen with complex applications that the scripts created are not looked at for a long period of time, structuring scripts using comments is essential - in teamwork anyway.

General comments in the script header

At the beginning of the script there should be a general comment block in which the author, the date, contact details and the description ( task from the Script) are noted.

# -------------------------------------------------------------------------------
# Jens Liebelt
# May 2011
# web@jens-liebelt.de
#
# FM4Web
# Create slider for the page header of the web edition.
#
# This script changes the layout.
# When called as a partial script, the calling script must return to the
# original layout.
# -------------------------------------------------------------------------------

History in the FileMaker script

If the script is changed during the development of the Database is changed, a comment block can be inserted for the history. The history shows which changes were made when and who made the changes.

# -------------------------------------------------------------------------------
# History
#
# 21.05.2011 Bugfix
# Jens Liebelt
# Incorrect state of variable $_filename after execution
# from the subscript Calculate image size.
# -------------------------------------------------------------------------------

Variables in the FileMaker script

Complex scripts generally use variables for process control and the calculation of field values. In principle, this option should always be used - however, it is necessary to decide on a standardized spelling and designation for variables. Global variables should be used sparingly and initialized in a partial script so that you can always see which global variables are used in the application. Local variables whose validity is limited to the current script should be noted in a comment block.

# -------------------------------------------------------------------------------
# Local variables
#
# $_filename
# $_filepath
# $_fileisuffix
# -------------------------------------------------------------------------------

Script parameters

The use of partial scripts and local variables often requires the use of script parameters (arguments). In this way, the value of a local variable can be passed to a partial script without losing the initial value in the current script - if required, the current value can be replaced by the result of the partial script (Get ScriptResult).

# -------------------------------------------------------------------------------
# Script parameters
# $_filename - Pass on to subscript Build file name
# $_filipfad - Build pass to subscript filename
# -------------------------------------------------------------------------------

Script sections - Structure of the script

The sections in a script should be commented in blocks. This means that each section that represents a self-contained sequence of commands is summarized in a comment block.

#--------------------------------------------------------------------------------
# Slider 1
# Further explanations can also be placed here,
# this depends on the complexity of the block.
#--------------------------------------------------------------------------------
If [ Server::_slider pic 1 ≠ "" ]
Set variable [ $_filename; value: "slider_1" & characterRight ( Server::_slider 1 imgPath ; 4 ) ]
Export all field values [ Server::_slider pic 1; "file:html/images/slider/$_filename" ]
Set variable [ $_slider; value:$_slider & "/>¶" ]
End (if)
#--------------------------------------------------------------------------------
# Slider 2
#--------------------------------------------------------------------------------
If [ Server::_slider pic 2 ≠ "" ]
Set variable [ $_filename; value: "slider_2" & characterRight ( Server::_slider 2 imgPath ; 4 ) ]
Export all field values [ Server::_slider pic 2; "file:html/images/slider/$_filename" ]
Set variable [ $_slider; value:$_slider & "/>¶" ]
End (if)

Important individual steps can then also be commented on. Comments should help and not confuse. There is no point in commenting meticulously on every script step, as this disrupts the flow of the source text enormously. In any case, comments, when used correctly, are an important tool for ensuring an overview of FileMaker solutions even years later.

Author: Jens Liebelt

Leave a comment

Share this page:

ERP software as flexible as your company.
We will be happy to advise you.

Customizable ERP software for Mac, Windows and iOS.

You are here: Using comments in FileMaker scripts for meaningful structuring.