MightyData

FileMaker and WordPress Consultants

  • Company
    • About
    • Contact
    • Team
    • Artists
  • Services
    • Consulting
    • Development
    • Our Process
    • Coaching
    • Training
  • Results
    • Customers
    • Success Stories
    • Testimonials
  • Blog

12 Days of FileMaker 12: Script Trigger Enhancements

May 14, 2012 by Susan Fennema Leave a Comment

Using Script triggers has become common place in FileMaker development — and with the new enhancements in FileMaker 12, we have even more power.

Script Trigger Enhancements in FileMaker Pro

In this session from the 12 Days of FileMaker 12, we look at an update to Script Debugger in FileMaker Pro Advanced for globally enabling/disabling triggers, as well as new indicators, and new triggers.

About Sameer Khan

Sameer Khan is the presenter. He is a FileMaker 9-11 Certified Developer and Authorized Trainer employed by Anvil Dataworks, a development firm outside of Washington DC. He has been working with FileMaker for over eight years. His students say that he is an interesting person and a knowledgeable teacher.

Filed Under: Scripting Tagged With: 12 Days of FileMaker 12, FileMaker 12, Script triggers, Video

FileMaker Server-Side Scripts: File Paths

March 9, 2012 by Anders Monsen 3 Comments

Folder structure for server files

In an earlier post I wrote about FileMaker Server’s ability to combine system scripts, or shell scripts, with native FileMaker scripts. This shows one of the many ways that FileMaker integrates with external systems, one of the great benefits of working with FileMaker. Yet aside from integration, FileMaker’s server-side scripting also runs native FileMaker scripts. This can off-load many tasks currently assigned to robot boxes, computers whose sole purpose is to connect to FileMaker Server, mimic a user and run various events. With enhancements in FileMaker Server 10 and 11, a veritable movement has risen in the FileMaker community to stomp out robot usage in favor of handling such events through FileMaker Server instead.

There are advantages to running regular tasks through Server. Robot boxes take up resources. The computer running scripts might be better served elsewhere. Security considerations also play a part. Where does the robot box sit? Is it a headless box in a server room, or on someone’s desk? If the robot goes down or fails, how quickly will this be noticed? What about backups? Moving the scripts to server might remove some of this concern.

FileMaker’s Knowledge Base contains a couple of brief entries on server-side scripting, one defining the issue, another looking at differences between client and server-side scripting. Referring to these documents while setting up server-side scripting provides a nice overview of options and things to consider, but there are additional caveats.

External File Paths

Consider the server folder structure. Organizing databases into folders both gives a visual overview of separate types of files, and helps break down the backup process into more discrete parts. While relative file paths like file:filename.fp7 will still find other files, even across separate folders, they will break with server-side scripting across multiple files.

Folder structure for server files

To test this issue, I took a copy of SeedCode complete, which uses three files, and split these into two folders, one for the data, and one for the UI. This will mimic a situation where running backups on the UI might differ from the data files. I then created a script in the UI file that found records in the data file through the External Data Sources. This script worked perfectly when the files were in the same folder. When you separate the files, the server side script failed. This failure showed in the Schedule view, under status – “FileMaker Script error”.

Server-side script error

To see what happened, I swithed over to the Log Viewer and enabled Server Events. There you can get more details about any errors. In this instance it showed error 100: File not Found.

Server-side script error

The recommended solution is to address the folder in External Data Sources, in addition to the relative path.

I first tried listing just the folder name:

file:SeedCodeData/SeedCodeData

This failed, as did adding a dash in front of the folder name. The solution, recommended by Lisette Wilson, was add two periods in front of the folder name, something quite typical in PHP include files (as well as HTML). The new format looked like this:

file:SeedCodeData
file:../SeedCodeData/SeedCodeData

When I ran the schedule again – no errors! Actually, there was one small error. Since any OnOpen script also runs, I had modified the script to look for Get ( ApplicationVersion ) = “Server”. This would bypass the regular process and skip any incompatible steps. Yet, I still got an error indicating the opening script was still running. The actual calculation result was “Server 11.0v4”. Once I adjusted for this, there were no errors in the Event Log.

Server-side script OK message

Conclusion

This process illustrated some of the frustrations with server-side scripting – there is no Script Debugger when running a server-side script. Even if the Event log shows no error, there may still be unknowns in the process that need to be debugged. To deal with this I often build an event log table, and populate this with information from the script during testing. Also, the exact format of the folder path in External Data Sources took a while to track down. Still, with caution and planning, the possibilities opened by server-side scripting are well worth investigating.

Filed Under: Scripting Tagged With: Server-side scripting

FileMaker Server-Side Script Sequences

February 22, 2012 by Anders Monsen 1 Comment

FileMaker Server script types

FileMaker solutions often employ what’s know as robots–computers that run FileMaker scripts so that users do not need to execute scripts manually. The release of FileMaker Server 9 debuted server-side scripts, which can reduce the need for robots and take advantage of Server schedules. In this post I’m going to take a brief look at this scripting option.

FileMaker Server script types

In FileMaker Server, when you select “Run Script” there are three kinds of scripts available:

  • FileMaker script
  • System-level script
  • Script sequence

As with any instance of limited resources, decisions must be weighed before proceeding. FileMaker Server has a limit of 50 schedules. System-level scripts can be run as cron events (Mac OS X) and system events (Windows), so these scripts might not be the best use of FileMaker Server’s schedule resources.

Running FileMaker scripts can off-load client processes onto the server, thus eliminating the use of robot machines. Script sequences allow a mix of both worlds, since you can script both FileMaker and the OS to run repetitive tasks.

Getting Started

Setting up schedules takes place in the Admin Console, which has a series of easy steps to create a schedule. Once you have selected “script sequence” for the type, you’ll see a list of databases along with a place to enter an account to access the database.

Select script dialog

Since a database is usually accessed by FileMaker Pro, special consideration is necessary to run scripts server-side. A file with an OnOpen script needs to take Server into consideration. One option is to use Get ( ApplicationVersion ) and exit the opening script if the result is “Server”.

After the database and account are entered, you select the script that the server will run. (Adding an option to filter for scripts like the Manage Scripts dialog in FileMaker Pro might be a nice future enhancement for FMS.) As with FileMaker Pro, you also can specify an optional parameter.

Setting Sequence Permissions

The next step is to select the sequence options, which is where it gets interesting. Here you can select system-level scripts to run before and/or after your FileMaker script, along with any system-level parameters (see below). Importantly, you also select the account to run the system-level scripts. On Mac OS X this is important because it must match the permissions on the system-level script inside the Scripts folder for FileMaker Server.

Script sequence dialog

Since the default account is fmserver, you should set the system-level script username to fmserver and the group name to fmsadmin. The drop-down will let you select any script in the Scripts folder, but permission issues can cause errors in the execution of the schedule. An enhancement in FMS 11 allows you to set a time limit on the schedule, which can be helpful when a script sequence may run too long and collide with subsequent schedules. In the example below the FileMaker script runs after the shell script. Other examples might have a shell script run first, followed by a FileMaker script, then another shell script. This could involve some method to load and transform data, then export and move the data via the OS. This opens many additional possibilities for FileMaker integration.

Conclusion

Unfortunately, large aspects of server-side scripts remain in a black box environment. Error messages aren’t always clear. The script may fail and the Schedule status shows a FileMaker error. Checking the Log Viewer usually provides more clues, such as Error 100 for file not found, or another FileMaker error. Sometimes the status may be OK but the shell script portion fails, which requires troubleshooting outside FileMaker. Agnes Riley of Zero Blue wrote a post in 2010 covering some of the caveats. Despite these cautions, server-side scripting has tremendous benefits and power.

A subsequent post will look more closely at running FileMaker-only server-side scripts. Does your solution use sever-side scripts? What are some of the best practices and problems you encountered?

Filed Under: Scripting Tagged With: Admin console, Best practices, Server-side scripting

ImageMagick and FileMaker

February 2, 2012 by Anders Monsen 4 Comments

A few months ago I wrote a piece on image manipulation in FileMaker container fields on Mac OS X. That type of manipulation was relatively simple – rotating an image – but required AppleScript and ImageEvents. What if you required a more complex adjustment of images, such as converting from TIFF to JPEG, or compression, blurring, re-sizing?

Image Events actually does some of these types of manipulation, but not always with expected results. Many people turn to Photoshop for these effects. You can also write AppleScripts to interact with Photoshop and FileMaker, but may end up dealing with syntax changes or application version changes. Photoshop also must be open and active, and is expensive.

Another option we looked into was ImageMagick, a powerful and free open source command line tool that also will work with multiple programming language like PHP, Perl, Ruby and others.

Installing ImageMagick

Installing ImageMagick on the Mac requires time and patience. Apparently the people who support this (free, by the way) software only maintain the latest OS-compatible version as an executable installer – meaning Mac OS Lion. The machines that would run this were still on Snow Leopard, so this required a more manual method.

The Mac OS X binary release requires MacPorts, which in turn requires XCode. These first must be installed and configured correctly. MacPorts, once installed, also required a self-update (sudo port -v selfupdate), which in our instance required tweaking rsync settings due to firewall issues. Alas, this step is poorly documented, but in our instance we changed this document: /opt/local/etc/macports/source.conf

By commenting out the last line, which uses rsync, and adding a direct url, we were able to get MacPorts to update properly.

# rsync://rsync.macports.org/release/tarballs/ports.tar [default]

http://www.macports.org/files/ports.tar.gz [default]

Then in the Terminal, we typed the following. Then we sat back and enjoyed many minutes of peace while ImageMagick installed, as this took a while.

sudo port -d sync

Finally, installing ImageMagick itself was a one line command in the Terminal:

sudo port install ImageMagick

Once installed, you can test ImageMagick by running “convert-version” in the Terminal. If properly installed, you will get something like the following:

"Version: ImageMagick 6.7.2-0 2011-09-20 Q16 http://www.imagemagick.org Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC Features: OpenMP OpenCL"

Integration with FileMaker

Since it now worked in the Terminal, it was time to turn our attention to integration with FileMaker. For this to work we needed to execute a shell statement from FileMaker. As this solution already used Troi File, which has a function to execute shell, we just needed our command. Troi File’s command TrFile_ExecuteShell( ) is used to send commands to ImageMagick. Prior to each shell action we built the command in a variable, which let us debug this in the Data Viewer.

To complicate matters, certain ImageMagick actions returned values, while others returned nothing. For example, the version command returned the string inside the execution step, so setting a variable to TrFile_ExecuteShell populated this variable with the result. This was a perfect way to test whether or not to continue, since computers without ImageMagick installed would not be able to perform anything, and we could exit gracefully if the version command did not contain any ImageMagick information.

There are several commands that we can send to ImageMagick. Each command accepts different arguments. For example, “identify” provides information about the image, while “convert” performs the actual conversions. The shell command string requires the full path to the command, which usually is inside the “/opt/local/bin/” folder.

Our primary requirement was to convert an image from one type to another, filtering and resizing the image to certain specifications. The beauty of ImageMagick and shell scripting is that you can point to a source image across the network and send the converted file to another location across the network.

The convert command uses certain parameters such as source file, resize and resize value, and where to write the file. An example of this with some fill-in-the-blank naming appears below.

"/opt/local/bin/convert path_to_source/filename.TIF -set option:filter:blur 0.8 -resize %RESIZE_VALUE% -strip -quality 90 -write \"path_to_destination/filename.jpg\" +delete"

Alas, this command returns nothing from within FileMaker. There is no way to know whether or not the conversion was successful, aside from a second command using Troi File to see if the new file exists.

Conclusion

While there are significant cost and overhead advantages to using ImageMagick over, for example, Photoshop, there is a corresponding cost in terms of time and effort. The command line doesn’t always invite users to have a great experience.

While I have not tested these features, Monkeybread Software’s plugin for FileMaker comes with image editing using GraphicsMagick, a fork from ImageMagick a few years back. Other plugins provide execute shell commands, so you’re not just limited to Troi File.

Trapping for errors remains important, as sometimes you get feedback, and sometimes nothing, from within FileMaker. Usually you can copy the command from the Data Viewer into the Terminal, and then you will get some feedback about any errors. That said, this is a powerful method to integrate image manipulation into FileMaker.

Filed Under: Scripting Tagged With: Command line, ImageMagick, Integration

Brainstorming Your Way To The Solution – Part 2

October 25, 2011 by Brad Stanford Leave a Comment

In Part 1, I explained how I started exploring different options to meet a customer request for a specific report (not a standard subsummary report) with acceptable performance (not a resource hog or more than a minute to display).

Combine the Knowns to Solve the Unknown

By thinking through all of the tools and methods I had tried or read about, I was able to assemble a list of the steps I needed to take, and what tool or technique to use on each step:

  1. Gather all the parent and child IDs – GetNthRecordSet( ) function
  2. Convert the sort-able data that references a giant value list to a number that can be sorted easily – Position( ) function
  3. Set the IDs and sort numbers directly in the report records – via portal, to avoid the commit problem (transactional commit)
  4. Report layout – Display related data in dummy records to cut down on CPU usage (similar to virtual list technique)
  5. Sorting – Sort on numbers that have been set into fields by a script, rather than sorting a related field based on a related value list

Here’s how that gathering of tools played out in real life:

  1. Go to the list view of the parent records.
  2. Enter a loop with a variable ($Counter) set as a counter. $Counter will be used later to sort the records into the order they were encountered.
  3. Loop through the parent records using the GetNthRecordSet( ) function, using the counter variable to determine which record to look at.
  4. On each parent record, append a global variable ($$Keys) with the parent record’s ID, two pipe characters (placeholders), and $Counter.
  5. Begin a second loop with its own counter. Using the parent/child key, loop through all the related child records and append $$Keys with: the child record’s ID, the sort order required by a large, user-generated value list, and the parent record’s $Counter.

The calculation for the sort order based on the giant value list is simply:

Position (
	ValueListItems ( "GiantValueList" ; "File.fp7" ) & "¶" ;
	ItemFromChildRecord & "¶";
	[starting at] 1;
	[occurrence] 1
)

This converted the item name to a number, based on where it was found in the value list. So instead of sorting on a related field based on a related value list, I would simply sort on a number field set by a script.

By this point in the script, I will have collected all the values I need. The data looks like this:

1096718||1
471067|362|1
471068|131|1
471069|438|1
471070|48|1
471071|779|1
471072|337|1
8721684|738|1
1096732||2
419861|131|2
2458113|48|2
2458114|3998|2
2459828|779|2
8721807|738|2
1096733||3
575704|362|3
575705|438|3
575706|48|3

Decoded, it means:

Parent Record
RecordSerial | | SortOrder
1096718 | | 1
Child Record
RecordSerial | PositionInValueList | SortOrder
471067 | 362 | 1

All that’s left to do is to loop through the report records and set the fields. Once the key fields are set for either parent or child records, a relationship is established, and I can display whatever I want from that record. In this way, I’m not moving all the data, just the key fields allowing me to place related fields on the report layout.

I’m also setting the sort order in a number field, which will let me group parents and children together. The middle value of the child record data represents the sub-sort order below the parent.

Setting Fields Quickly

When I was setting fields before, I had problems with committing records taking up time. Once again, Todd Geist (and this time, also Jason Young) to the rescue. Looping through a portal does not commit the records as you move from record to record. So I created a third relationship, a one-to-many self-join, using a global key field:

Reports::zzgk_NumberOfRows = Reports::zzk_Row

where Reports::zzk_Row is a pre-populated field.

For the relationship, it’s a text field that was set to the record number of the record in question at time of creation. For sorting, there’s a number version of the field. (And in this scenario, I went ahead and created 30,000 records in advance. That’s probably enough for almost all scenarios for this particular report.)

So now, to continue with the script concept:

  1. Go to a layout based on the Report table that has a transparent scrolling portal based on the Reports::zzgk_NumberOfRows = Reports::zzk_Row relationship. There are no fields in the portal, for speed’s sake.
  2. Set field Reports::zzgk_NumberOfRows to (PatternCount ( $$Keys ; “¶” ) + 1 ). This tells the portal how many rows of report records to show.
  3. Loop through the portal, setting either the parent key and clearing the child key (from the last time the report was run) or vice versa: set the child key, and clear the parent.
  4. While in that portal row, also set any and all sort values.
  5. Exit the portal, commit the record, and all the changes are committed at once.
  6. Navigate to the actual Report layout, and sort the records based on the Parent’s sort number – which places all the parent and children records together in the order that the user had originally sorted the parents – and then sub-sort by the value list sort number for the children records. Because these numbers are set by the script rather than calculated on the spot, they sort very quickly.
  7. Enter preview and present the print dialog.

The fields on the Report layout are actually related fields from the parent and child. Each report record has both sets of fields in the body. If it’s a parent record, the child fields are empty, and set to slide and shrink the enclosing part (the body). If it’s a child record, the parent fields collapse out of the way, and the body once again shrinks. In this way, I just tell a record what it is and use sliding to make it look right.

To make it clear which is which, I put conditional formatting on the parent record:

[ Not IsEmpty ( Self ) ; Turn the parent fields gray ]

This twelve-step process did the trick. And it was much faster than anything I had built before it. Better still, it worked!…Well, almost.

I started having trouble with “ghosting” — that is, when a relationship continues to show the last value it showed, even though the relationship key has changed. As best as I could tell, this was simply some freaky by-product of walking through the Report records through a portal. Like I said before, when you’re innovating, you never know what FileMaker is going to bless or curse.

My solution here was to mirror other processes in this solution and open a small window in which to do the search and set with the fields. Then, when the report was set, I would close the temporary window, and navigate to the report once I was back in the original window. This worked like a charm.

Time for Some Speed Tests

Here are some results based on small-found-set tests that I ran:

  • 272 parent records / ~ 4500 children records – Elapsed Time: 2:45
  • 213 parent Records / ~ 2770 children – Elapsed Time: 3:35
  • 126 parent records / ~ 830 children – Elapsed time: 0:42
  • 208 parent records / ~ 1540 children – Elapsed time: 1:10

The apparent lack of consistency is from variations in the amount or type of data being referenced.

But the times are well under the five to ten minutes my very first scripts were showing. And the CPU dropped from 100+ percent solid for five minutes (sometimes peaking at 190%) to 15% peaking at 30% here and there, running under three minutes most of the time.

That, for me, was the process of brainstorming my way through this problem. I expect there to be some forehead-slapping suggestions like, “Why didn’t you just use the MagicDoWhatINeed( ) custom function?” And my answer will be the same to all suggestions: “Next time, I probably will!”

The point is to try to demystify the innovation process in a continuing effort to become better developers. Also, to encourage everyone to continue chasing down those difficult problems and making them submit.

The bad news: it’s just a lot of hard work sometimes. The good news: if it’s hard, then many will avoid it. That means the playing field is open to whoever wants to be the next famous FileMaker innovator, and acquire the related spoils.

Filed Under: Scripting Tagged With: Guest post, Performance, Reporting

Taming the Virtual List – Part 2

October 17, 2011 by Lisette Wilson 14 Comments

Part 1 provided a broad outline of the Virtual List Technique. Part II will step through a specific example of how this technique solved a MightyData customer’s request.

Requirements

This customer needed a sales order and invoice tracking system, and provided a sample of the current sales order in Excel. I mimicked this layout in FileMaker, with a header showing purchaser details, a body for line items, a subsummary by purchaser for order totals, and a trailing grand summary for a page of legal language. The customer had to submit these sales orders to another department for processing, and they required a specific format. The section with totals needed to appear on every page except the final page with legal language; however, the totals themselves should only be shown on the last page of line items, with the boxes blank or reading “Continued…” on preceding pages. Each page with line items should show 4 line items, even if some were blank.

In a basic FileMaker format, if there were more than 4 line items to the sales order, all line items would be included on the first page, and the subsummary section with the order totals would be pushed to the next page. The requirement for the blank lines made using the line items themselves problematic. Even an order with 3 line items, that would otherwise fit the format, would not have that blank fourth line.

Table Structure

This database started with a foundation of the SeedCode Complete template, so the building blocks for the Virtual List were already in place, in the CalendarRows table of the Interface file.

I added a global text field to the CalendarRows table (gInvoiceID) and created a relationship from CalendarRows to a new RowsInvoices table occurrence based on the InvoiceLineItems table (a sales order become an invoice by a change in the status).

Layout Modifications

I duplicated the current layout for the Sales Order, changed layout context to the CalendarRows table, and repointed the fields in the header and subsummary to the related Invoice fields. The line items will be fields in the CalendarRows table, which pull values from the Virtual Lists, and is covered in more detail later.

The script begins on the Sales Order layout, and line items are shown in a portal. The Sales Order should reflect the following details about the line items:

Scripting

In this case, values are required for each of the line item fields, so we can use the List function from the context of the Sales Order layout to build global variables for the Virtual List. If it were possible for a record to have no entry for a field, the list function would not be suitable, without a utility calculation field to ensure a value for each record. If so, I would have looped through the portal rows to build global variables, representing a blank field with a blank line in the global variable value list.

Set the global field (CalendarRows::gInvoiceID) to the primary key for the Sales Order.  Then set the following global variables:

$$sc_Qty = List ( InvoiceLines::Qty )
$$sc_Desc = List ( InvoiceLines::ZDisp_LineDescription_ncr )
$$sc_PriceEa = List ( InvoiceLines::PriceEa )
$$sc_LineTotal = List ( InvoiceLines::PriceLineTotalCalc )

You may be wondering about zDisp_LineDescription_ncr. The line description is built of several fields with some text identifiers, and includes carriage returns. Since the Virtual List relies on getting specific values from the value list, we can’t have carriage returns within the data. This calculation field substitutes a text constant for the carriage returns. That process will be reversed in the calculation to extract the values.

Four more fields were added to the CalendarRows table, to extract the values from the global variables above. Three of the four simply pull the value from the global variable based on the number in the RowNumber field. SalesOrderDescription_c handles that carriage return we needed in the description by reversing the earlier substitution. These four fields are the body of the layout. The fields are four lines tall, with a border. The lines shown within each field are overlaid line elements.

Count the number of values in one global variable to determine the number of line items. Divide this by 4 to determine the total number of pages, and set the initial page value to 1.

Set a variable to the filename to be used for this document, and set the path to:

$path = “file:” & Get ( DesktopPath ) & $filename

The script then loops to find rows in groups of 4 until all pages have been printed. Using Save As PDF for the first page, then Append PDF for subsequent pages. In PDF Options, specify page 1 of 1 until the final page, then include all pages. By always finding 4 records, we will have blank rows when there are fewer than 4 rows with data.

virtual-list-print-loop

The $$lastpage variable is set to 1 for the final page. This allows the script to include all pages, as noted above, and also drives the conditional formatting.

Remember the requirement to only show the totals on the last page of line items? “Continued…” with transparent background overlays each of the total fields. When $$lastpage does not equal 1, the background is changed to white, so that the totals cannot be seen. Some of the totals should only be blank, and for those, the text is also changed to white. When $$lastpage equals 1, the only change is for the font size to be made very large, so large it cannot be shown in the tiny space allotted to the text, allowing the number field beneath to be seen.

Summary

The Virtual List Technique is versatile.  Developers are using it to create amazing solutions. Think of the global variables as columns, with each individual value in that list as the row data. Looping scripts can gather data from portal rows, or a found set of records, or several found sets of records. The data can be simple or complex. Use the GetSummary function to gather summary data, such as totals, averages or percentages, for a cross-tab report. Understanding the basic concepts of the Virtual List Technique is the key; with that foundation and a little imagination, you can solve any number of reporting and display challenges.

Filed Under: Scripting Tagged With: Guest post, Reporting, Virtual list

Taming the Virtual List – Part 1

October 7, 2011 by Lisette Wilson 6 Comments

Have you ever wanted to create a report in FileMaker, but found it just doesn’t work that way? Perhaps you need to combine disparate data from several tables. Or export data where several records are combined into a single row. Or show totals both “across” and “down”, with a pivot table. Or format an invoice so that a set number of rows appear on each page, with a header and summary totals on every page. With the Virtual List Technique, you can achieve all of these and much more.

What is the Virtual List Technique?

It’s a powerful tool cooked up by Bruce Robertson of Concise Design. Put simply, you use a looping script to build a value list in a global variable, and each value or row becomes a field value in a record in a utility table.

It’s somewhat similar to using a dedicated reporting table, where you create records and set fields, but in this case, the values are short-lived. The Virtual List Technique has several advantages.

  • No need to create and destroy records, or track records for this particular report.
  • Multi-user friendly. Since data is stored in global variables, it’s unique to each user. A dedicated reporting table would require overhead to ensure each user viewed only the records for that report.
  • Speed. Global variables live in RAM on the local machine, not on the server hard drive across the network.

It’s not just for reporting. SeedCode Complete utilizes this technique in the calendar displays and in “selectors” where the user is presented with a pop-up window to select a record in another table. fmSearchResults uses it to produce search results across multiple tables.

So, what do you need?

At a minimum:

  • A script (possibly a loop, but the List function is your friend) that builds a return separated value list in a global variable [$$array].
  • A utility table with as many records as rows in your reports. (100 records have sufficed for my needs thus far, but use as many as you need.)
    • A number field filled sequentially (1 to 100) [Row]
    • An unstored calculation field to extract values from the global variable
      [ GetValue ( $$array ; Row ) ]
    • A layout with context of the utility table showing the unstored calculation field, or a portal pointing toward that table.

This versatile technique can be expanded by using multiple global variables and unstored calculation fields, repeating global variables, conditional formatting, and even images stored as a reference. Add this foundational skill to your FileMaker toolkit, and you may never answer a reporting request with, “FileMaker doesn’t work that way,” again. In Part 2, I’ll walk through a specific example of how this technique solved a MightyData customer request for a sales order formatted with a set number of rows on each page, and header and summary totals on every page.

Filed Under: Scripting Tagged With: Guest post, Reporting, Virtual list

3 FileMaker Demo Files

October 5, 2011 by Martha Zink Leave a Comment

Golden Gate Bridge

I presented these demo files during a series of user group meetings in the Bay Area. My goal for each demo file was to incorporate the technique into an existing solution and think of it outside of the box.

Snapshot Link

In this sample file, there are two applications of Snapshot Link:

  1. Launch file
  2. Bookmark when closing

For the launch file, open up the solution. Once you’re at the opening screen with the “About” and “Demo” buttons, create a Snapshot Link and place it on your desktop. As long as the file doesn’t move, the Snapshot Link on the desktop can serve as your launch file.

For the bookmark, there is a script called “On Close” that runs when the file closes (via File > File Options). It shows a dialog and asks the user if his place should be saved. If the user agrees, the script puts a Snapshot Link to the desktop, that the user can click to start off where the database was last left.

Demo File: Snapshot-Link

Filtered Portal

In these sample files, there are two treatments of Filtered Portal:

  1. New approach to tab control
  2. Report management

It’s common to create a solution with tab controls, but what if you wanted to change the look? The layout “Sample Menu | Tab no Hierarchy” shows you how a filtered portal can enhance the user experience and control the tabs. This technique takes a combination of the following:

  • Hidden Tab Control (Fixed Width of tab = 0) where each tab has an object name
  • The table “Tab” that stores the tab display name, the menu group, the sort order, and the object name for each menu.
  • The script “SwitchTabs”  takes the user to the correct object based on the object name stored in the Tab table.

The layout “Sample Menu | Tab” takes the technique to the next level, allowing a hierarchy of parent and child. The added tools for this technique work include:

  • A field in the table “Tab” called “Belongs To” that ties each record to its parent record
  • A global variable that contains the “Belongs To” value for the filtered portal

The other sample file for filtered portals shows how to use a filtered portal with global fields. Not only is the user interface clean, but the user has control over which reports he can see. You’ll notice the “Not isEmpty( )” in the Filtered Portal calculation. One of the things I’ve learned over time is that if the user selects nothing in a filter, he or she wants to see everything. It is counterintuitive but the expected behavior. Filtered Portals require quite a bit of trial and error.

Demo File: Filtered-Portal

Script Triggers

The latest version of FileMaker Pro introduces a few new triggers. In these sample files, there are several purposes for Script Triggers:

  1. OnViewChange – Changing views (meaing layouts) with the Toolbar
  2. OnObjectValidate – Providing feedback for erroneous data
  3. OnObjectKeystroke – Limiting keystrokes and characters

In the first sample file, the script “Change in Views” is being triggered by OnView Change. If the user clicks on the “list view” from the toolbar, the script is executed, taking the user to a layout with the same data in a list view. The same applies in table and form view. The important part of the technique is consistency in the layout naming. Each one ends with the word that defines the layout view.

In the second sample file, there are three examples:

  1. OnObjectValidate – Allowing a range based on the script parameter (Example: 1 to 10)
  2. OnObjectKeystroke – Not allowing the user to type anything but positive numbers (including the decimal point)
  3. OnObjectKeystroke – Not allowing the user to type anything but numbers (including the dash for negative numbers)

There is also an example involving the drop-down. One of the things my user discovered was the ability to type into the field if the drop-down wasn’t showing. By using OnObjectKeystroke, the user is limited to what keystrokes will occur.

However, it is important to note that individual keystrokes are allowed, even though they don’t produce a character. These keys include backspace, return, escape, and arrow keys. Removing these from the user’s capabilities would leave the user feeling handicapped instead of improving the interface.

Demo File: Script-Trigger

Filed Under: Scripting Tagged With: Demo file, Filtered portals, Script triggers

Validation With Script Triggers

August 26, 2011 by Martha Zink 2 Comments

With the post-DevCon madness coming to a slow end, I’m excited to announce that I’ll be traveling the last week in September and participating in the West Coast FMPug Tour! What’s the schedule you ask? Here it is:

  • September 26 – Seattle
  • September 27 – Portland
  • September 28 – San Francisco
  • September 29 – FileMaker Inc. (the Wedge in Santa Clara)

With that said, I’d like to share with you one of the techniques that I’ll be presenting at the FMPugs – and that’s controlling the user via script triggers. Now I say this cautiously, as I can feel Steven Blackwell rolling his eyes at me from 1500 miles away, concerning himself with Security (and rightfully so!). I do not think that script triggers should be the only means for controlling users and the data they enter, but I do believe that script triggers can give the user a more pleasant experience than JUST validation. I implemented this technique for one of our development customers and they are very happy that their solution is intuitive and the data being entered is accurate. So onward! One of my critiques of validation error messages is their… simplicity. You get a dialog box and a couple of buttons – that’s it. With this example, we can use script triggers to give the user more information and allow them to enter data accurately.

Example 1: Better Dialog Messages

A great use of script triggers is OnObjectValidate, which runs right before validation occurs, which also means the user hasn’t left the field. Imagine having a field where the user has to enter a number between 0 and 100 and the user enters 150. With validation turned on, an error message will show up, but we can add a little more finesse with a script trigger. Here’s what the script looks like:

You’ll notice the use of Get ( ActiveFieldName ) and Get ( ActiveFieldContents ) – the goal here is to abstract the script so that it can be reused in multiple places. In other words, by not tying the script to a specific field, this script can be applied to multiple fields that require the same type of validation. So in plain English, what is the script doing?

  1. Checking to see if the value in the active field is between 0 and 100
  2. If the value is not between 0 and 100, a dialog box shows up with a global field in it. The user can then enter a value in the dialog.
  3. If the user enters a number between 0 and 100, the active field gets set to the value in the global field and the script ends.
  4. If the user enters a number outside of 0 and 100, the custom dialog keeps showing up.

Here’s what the dialog box looks like:

Example 2: Locking the Keyboard

My customer said to me, “I don’t want the user to even be ALLOWED to enter the wrong values with the keyboard.” This is a different approach to a similar problem. Instead of telling the user that he or she did something wrong after the fact, limit what the user can do during data entry.

In this same example, here’s a script that doesn’t allow the user to enter anything but numbers and periods (for decimal places). Now this was initially tricky in that I first wrote this to ONLY allow numbers and periods, but then realized that those aren’t the only keys a user might need while in a field. The other keystrokes that I had to allow were the tab key, and enter key, and the arrows (for navigating within the field).

Note: The script was put into a text editor for ease of reading.

The Let function is the most complex part of this script so let me break out that calculation:

 Let (
	c = Code( Get( TriggerKeystroke ) ) ;
	
	Length ( Filter (  Get ( TriggerKeystroke )  ; "0123456789." & If ( Get ( ScriptParameter ) = "dash" ; "-" ; "" ) ) ) > 0 or c = 9 or c = 10 or c = 28 or c = 29 or c = 30 or c = 31
)

The variable “c” is going to equal the numeric representation of the keyboard key.

The line starting with “Length” is checking to see if the key was a number, a period, and if the script parameter is the word “dash” then the dash, too.

As for the other codes, here’s the legend:

  • 9 – Tab
  • 10 – Enter (number pad)
  • 28 – Left arrow
  • 29 – Up arrow
  • 30 – Right arrow
  • 31 – Down arrow

The easiest way to tie the keyboard to a number is through the Keystroke Companion by SixFriedRice. A must-have in a FileMaker developer’s toolbox. So the script checks to see if the user hit an appropriate symbol or an appropriate keyboard key. If the user has, the script exits with a 1, meaning “OK”. If the script exits with a result of 0, the script trigger will prevent the keystroke from being executed. The cool thing about OnObjectKeystroke is that the script runs before the key is entered into the field, so the script has control whether or not the key shows up.

Clean. Elegant. User friendly.

The nice thing about implementing script triggers like this is that the user gets feedback on what’s right or wrong when entering data. One approach is from a preventative perspective, while the other warns the user when something needs to be fixed. It’s these types of techniques that can really make a solution clean, elegant, and user-friendly.

Filed Under: Scripting Tagged With: Script triggers

SyncDek: An Alternative for Audit Logging

July 14, 2011 by Kirk Bowman Leave a Comment

Three windows to view SyncDek under-the-hood

Auditing logging is a common request from customers—the ability to track database activity including adding, editing, and deleting records, who changed it and when. In some types of businesses, like medical and financial, the law requires it. Generally, there are two approaches to audit logging in FileMaker, either native functionality or a third-party tool.

WorldSync has two products that provide audit log functionality. FMDataGuard is a client-side (FileMaker Pro) plug-in that can log database activity using function calls in various calculation windows in FileMaker Pro (security, validation, etc.). SyncDek is a separate server application that communicates with FileMaker Server Advanced via JDBC to log database activity.

While FMDataGuard works well in typical situations, there are some performance considerations in high transaction and network environments. The reason is all the effort to log database activity happens client-side and must travel over the network in a multi-user environment. SyncDek provides a solution to performance issues because it moves a significant amount of the effort to log database activity to the server.

Case Study

Earlier this year we developed a new medical research database for one of the top cardiothoracic surgeons in the United States. Since the database contains “identifying” patient information, it must log database activity. We decided to implement FMDataGuard to meet these HIPAA requirements.

The database was deployed in a Citrix environment with FileMaker Server. During beta testing, the users reported slow performance that we determined was due to the overhead for FMDataGuard. Per the recommendation from Jason Erickson at WorldSync, we implemented SyncDek to replace FMDataGuard and the performance issues were resolved.

SyncDek Approaches

SyncDek is primarily known for database replication (syncing). However, it has additional functionality including backup recovery and audit logging. SyncDek offers a couple of different approaches to audit logging. The “PubFlag” method queries the status of the PubFlag field in each table to determine the activity to log. The advantage of the PubFlag method is that it is compatible with FileMaker Go (iPhone/iPad) and server-side scripting with FileMaker Server.

The “Live Posting” method uses the SyncDek plug-in (not the same as FMDataGuard) to push a request to log activity to the SyncDek server. The advantage of Live Posting is the auditing of activity can be near real-time. Live Posting also supports logging views, which the PubFlag method does not.

In our case we opted for the PubFlag method for logging adds, edits and deletes to move as much of the effort to the server as possible. Since logging views was also a requirement for this customer, we used Live Posting although the client-side impact to log views is light except for large found sets.

Digging Deeper

To gain a better understanding of what’s happening under the hood, I created a contact database with 5,000 records and implemented each method in turn. SyncDek uses a “temp” table in FileMaker to store requests to log database activity. It also stores the audit log in FileMaker (although it is could be a SQL table).

I opened the contact database from FileMaker Server and created three windows—one for the data entry layout, one for the temp table, and one for the audit log table. By creating, editing and deleting records in the data entry window, I was able to see SyncDek processing records in the temp table and creating records in the audit log table. If you implement SyncDek, I strongly recommend using this practice to see how SyncDek works.

Three windows to view SyncDek under-the-hood

To log deletes using the PubFlag method, WorldSync recommends using a custom menu to override the Delete Record and Delete All Records commands. The custom menu calls a script to change the value in the PubFlag field to “4” to mark the record for deletion. SyncDek then performs the delete and stores it in the audit log.

To log views using the Live Posting method, the Sync_LogView function is added to the limited View privilege for each table under Security. If you have three windows open, you will see SyncDek post a record to the “temp” table for the view. Then during the next cycle, SyncDek will track the view in the audit log table and delete the record from the “temp” table. Of course, this requires the SyncDek_TCP plug-in to be installed with FileMaker Pro.

Alternate Techniques

Once I had an understanding of how SyncDek works, I started experimenting with some alternate techniques. When the user performs a Find and SyncDek is logging views, it creates a View record in the “temp” table for every record in the found set. For founds sets of a few hundred records or more, this can have a negative impact on performance. My challenge was to determine a way to log a view for only the first record in the found set immediately after performing a Find.

My first idea was to use a custom menu, the same technique as logging deletes with the PubFlag method. This would override the default behavior of the Previous and Next commands in the Go To Record submenu. Unfortunately, the Previous and Next commands are not available in Custom Menus. Specifically, I wanted to use the “Based on existing command” option so logging would occur even if the user clicked the  “Go to previous/next record” buttons in the FileMaker toolbar. (Request to FMI: Please provide the ability to override all commands and subcommands in the standard FileMaker menus via Custom Menus.)

For my second attempt, I tried to create a limited View calculation to check a condition and decide whether to call the Sync_LogView function. I tried several variations including setting a global variable via a script or conditional formatting, and using the Get ( WindowMode ) function. Unfortunately, the order of execution in the limited View calculation does not return a consistent result. If there were a way around this limitation, there are several possibilities to implement this technique.

Example of a limited View calculation

For my third attempt, I setup an OnRecordLoad trigger to run a script with the Sync_LogView function. It works! The downside is the script trigger must be setup separately for each individual layout. Also, since it is implemented at the interface layer (layout) instead of the data layer (security), it may not meet the requirements in some regulatory situations.

On the upside, the script for the OnRecordLoad trigger, can be modified to work natively with FileMaker (without a plug-in). This replaces the Sync_LogView function by creating a record directly in the “temp” table. (I got this idea while watching activity in the temp and audit tables in the three-window scenario.)

Script to log "views" natively with SyncDek

Conclusion

Audit logging is one of three core features available with SyncDek. If you are already using the backup/recovery or syncing functionality, it is a no-brainer to use the audit logging, if you need it. If you are using FMDataGuard or another product/technique, SyncDek provides an alternative to address performance issues on the client-side.

Filed Under: Scripting Tagged With: Case study, Integration, Plugin

  • « Previous Page
  • 1
  • 2
  • 3
  • Next Page »
  • Company
  • Services
  • Results
  • Blog

Copyright © 2026