Portal Filter Scripting in FileMaker with Window Variables

Portal filtering can involve a number of small scripts for setting fields, clearing fields, and refreshing the portal. I’ve long been meaning to build one that would do it all, and that day has come!

This one script can be re-used anywhere without modification. Pass in some simple JSON to set one or more fields, one or more global variables, one or more window variables, THEN refresh one or more portals!

Wait… did someone say “window variables”? The attached file demonstrates that concept too. This allows you to have the same layout & record open in multiple windows, but have different filters applied in each window… cool!

This script uses FileMaker’s native JSON functions (introduced in version 16). I recommend using these for all your Script Parameter passing needs.

Example Script Parameter to clear one field and then refresh the portal.

JSONSetElement ( "" ;
[ "portal_name" ; "portal_object_name" ; JSONString ];
[ "set[0].field" ; GetFieldName ( Table::FieldName ) ; JSONString ]
)

Example Script Parameter to set 1 field, set 1 global variable, then refresh two portals.

JSONSetElement ( "" ;
[ "portal_name" ; "portal_object_name¶additional_portal_object_name" ; JSONString ];
[ "set[0].field" ; GetFieldName ( Table::FieldName ) ; JSONString ];
[ "set[0].value" ; "new_field_value" ; JSONString ];
[ "set[1].globalvar" ; "variable_name" ; JSONString ];
[ "set[1].value" ; "new_variable_value" ; JSONString ] )

You can pass as many fields, variables, and window variables as you wish. Just be sure to start at set[0], and increment by 1 for each additional thing you set.

Download the sample file. RefreshPortalScript.fmp12. Works in FileMaker 16+.

And there you have it! Do you see problems or have comments, questions, or suggestions for improvement? Please share in the comments!

While building this file I noticed what I believe is a bug in the “Refresh Portal” script step. The sample file compensates by using “Refresh Window” when window variables are used. I posted more details about this in the FileMaker Community.