The Execute FileMaker Data API script step in Claris FileMaker 21 has write operations using the action key with a value of create, update, delete or duplicate. This is part one of a series and I will show how to create a record using the Execute Data API script step in two different ways.

Our sample file has Companies and Contacts associated with that company. The New Company Button is just a utility script to create a new record. 

We are going to be looking at the scripts associated with the Add button in the row with Contacts. Clicking  Add will open a card window that is in the context of Companies. I’ll be using global fields for the Contact Info, for which I have entered some sample data. 

Add card window

Cancel at the bottom will just close the window and clear the global fields. The other two buttons – Save Basic and Save Reusable pass a parameter of basic or reusable to the controller script below. 

Controller script overview

Let’s start with the basic script Contact – Create New Record – Execute FM Data API.  A quick glance at the script shows that we are setting a variable for json, performing the call, and checking for errors.

Create new record script overview

Looking at the json we have a key for action with the value of create, fieldData, and field names. These live in the Contacts ( CON ) table including the foreign key for Companies ( CMP ) with the values set from the globals. Lastly, we have the layouts key which is set to the CON developer layout.

Example JSON

Before we see the result, let’s look at the reusable script Utility | Create Record – Execute FM Data API { json }. This script is similar, however, it is built to be used anywhere. So looking at the sample json there is a key for layout, and then keys for the optional fieldData. Also, if you compare the sample json here to the other script: you will notice the action key is missing, but it is getting set on line 22 of the script. Since this is only a create script, I chose to just update the json instead of passing it every time.

Create record script overview

Here is what the actual json looks like. This can be passed as a variable on line 17 of the controller script. 

JSON overview

And, finally, when clicking either Save button it creates the record as displayed in the portal. One thing to note: this sample file creates an uneditable version of the Contact. The next post in this series will show how to use the Execute FileMaker Data API to update records.

Record creation

Now you can go give it a try! Enter your info below to get the download and enjoy the rest of the week.