ExecuteSQL, Level: Advanced, SQL, Version: FM 18 or later

File IDs, Table IDs and Field-Level Schema

21 Jan 2021: demo has been updated to fix a couple bugs; article has been updated to reflect these changes.

Demo file:  file ids, table ids and field schema, v4.zip (requires FM 18 or later)

INTRODUCTION

Recently I was asked to help document a FileMaker solution by creating and populating a “schema” table as per the above screen shot.

One of the requirements was to programmatically determine internal ID numbers for the file and for the tables (as opposed to table occurrences) within that file, and this was accomplished by leveraging some script steps that were introduced in FileMaker 18.

(Thank you Rob Russell for pointing me in the right direction, i.e., to Save A Copy As XML.)

RUNNING THE DEMO

Clicking this button…

Continue reading “File IDs, Table IDs and Field-Level Schema”

Level: Intermediate, Version: FM 18 or later

A Value List Experiment

Demo file: a-value-list-experiment.zip

Note 1: today’s demo is recycled from the one that accompanied Virtual Portal, part 2. All we care about this time around is how we assign the parent company; the remainder can be ignored.

Note 2: if you’re unclear on value list basics, check out Thinking About Value Lists, part 1.

“I want it to work like it does in Quickbooks.” Based on a client request I recently implemented a Quickbooks-like picker… shown here enabling the user to easily assign a parent company via auto-complete as the user types the first few letters of the company name.

To be clear, we aren’t actually storing the parent company name, merely using it as a selection mechanism. When a name is chosen via this interface, the corresponding foreign key is immediately auto-entered into “id_parent”… Continue reading “A Value List Experiment”

JSON, Level: Advanced, Summary List, Version: FM 18 or later

Render Found Set as JSON Object

Demo file: found-set-to-json-object.zip (40MB; requires FM 18 or later)

[Author’s note: the demo file is a work in progress. Modify it as you see fit.]

Today we’re going to compare various methods one might consider employing to render an arbitrary found set as a JSON object. The demo consists of a table of US customers with 250K records, and the JSON object will be structured like so…

{ 
   State Name: 
      { County : [ [ customer array ] , [ customer array ] ... ] , 
        County : [ [ customer array ] , [ customer array ] ... ] , 
        ...
      } , 
   State Name:  
      { County : [ [ customer array ] , [ customer array ] ... ] , 
        County : [ [ customer array ] , [ customer array ] ... ] , 
        ...
      } , 
   ...
}

…i.e., grouped by state name and county, with customer data represented as a two-dimensional array, for example: Continue reading “Render Found Set as JSON Object”

JSON, Level: Advanced, Version: FM 18 or later, Virtual List

Virtual Portal, part 2

[Note: several hours after posting this article I realized the “Hide Object” calc could be streamlined. Screen shot and demo have been updated to reflect this.]

Demo file: virtual-portal-v2b.zip (requires FM 18 or later)

This is a quick follow up to the Virtual Portal article I posted the other day. As you may recall, the objective was to use virtual list to display disparate entities in a portal…

2019-12-26_154835

…via an array like this…

2020-02-16_18-29-04 Continue reading “Virtual Portal, part 2”

JSON, Level: Advanced, Version: FM 18 or later

FM18: JSON.InsertArrayElement

18 Sep 2022 – these custom functions have been upgraded – see JSON Custom Functions for FM 19.5, part 2 for details.

Disclaimer: the technique shown in this article is provided on an as-is basis. Use with appropriate caution and at your own risk.

Demo file: JSON-Array-Custom-Functions.zip (requires FM 18 or later)

201-08-23-animated

Have you ever noticed that FileMaker does not provide a JSON function to insert a new element into an existing array? For example, given this array (and bearing in mind that JSON uses a zero-based index)…

[ “A” , “B” , “C” , “D” ]

…JSONSetElement ( array ; 2 ; “XXX” ) will transform it to…

[ “A” , “B” , “XXX” , “D” ]

… but we have no native JSON function to “push” a new element into position 2 so that existing elements slide one position rightward to accommodate, like so:

[ “A” , “B” , “XXX” , “C” , “D” ]

Continue reading “FM18: JSON.InsertArrayElement”

JSON, Level: Advanced, Version: FM 18 or later

FM18: JSON.UpdateArrayElement

18 Sep 2022 – these custom functions have been upgraded – see JSON Custom Functions for FM 19.5, part 2 for details.

Disclaimer: the technique shown in this article is an attempt to work around an annoyance that can crop up when using FileMaker’s native JSONSetElement function, and is provided on an as-is basis. Use with appropriate caution and at your own risk.

Acknowledgement: I owe a debt of gratitude to Paul Jansen for many illuminating JSON-related discussions over the last year or so. Thank you Paul.

Introduction

Today we’re going to look at a custom function, JSON.UpdateArrayElement, written to circumvent a problem you may encounter when using JSONSetElement. (Note: see Thinking About JSON, part 1 and part 2 if you need a basic FM/JSON overview or refresher.)

Demo file: JSON-UpdateArrayElement-v3.zip (requires FM 18 or later)

2019-08-13_16-02-58.png

Why did I write a custom function to do what JSONSetElement apparently already does? Because under certain circumstances JSONSetElement does not work the way I believe it should. We’ll get to the custom function in a minute, but first there are a couple issues we need to examine. Continue reading “FM18: JSON.UpdateArrayElement”

Level: Intermediate, Version: FM 18 or later

New in FM 18: While, part 2

Today we’re going to dig a little deeper into the new-in-18 While function, and to avoid repetition, will assume readers are familiar with last month’s article on SetRecursion and While. We’ll look at some new examples ranging from basic to advanced, investigate the circumstances under which While can use variables previously declared via Let, and check out some benchmark results comparing While vs. CustomList.

Demo Files

Continue reading “New in FM 18: While, part 2”

Level: Intermediate, Version: FM 18 or later

New in FM 18: SetRecursion and While

Author’s note: Inevitable comparisons will be drawn between the new While function and the venerable CustomList custom function, which I wrote about at length several years ago. Preliminary testing indicates that CustomList is faster under certain circumstances and While is faster under others. In my opinion, both of them belong in your developer tool kit.

Today we’re going to take a look at two new functions introduced in FileMaker 18: SetRecursion and While, and you can follow along in today’s demo files if you are so inclined.

maclaurin-series.png

Demo files: While-Sandbox.zip and Maclaurin-Series.zip

Continue reading “New in FM 18: SetRecursion and While”