Here we are at the last part for this series. First, in Execute FileMaker Data API – Part 1 – Create we learned how to create records in a couple of different ways. Then, in Execute FileMaker Data API – Part 2 – Update the focus was on updating records. Finally, we are going to learn how to delete and duplicate.

If we look at the contacts portal below there are two buttons. One for delete and the other for duplicate. Were going to start with how we delete records. Originally, the script attached was just using the Delete Portal Row script step.

Instead of having both versions on the row it has been swapped to the new script called Utility | Delete Record – Execute FM Data API { json }. When looking at this script the format is similar to the others for Create and Update. When looking at this notice I am passing in the recordId with update and the action is set to delete on line 28. The only other info I added was messageType. This allows me to keep this universal by passing a description of what is going to be deleted. In this case it’s a Contact. Starting at line 28 is where the dialog pops open to display this. However, notice on line 25 it is also deleted from the json, because it is not needed for the Execute FileMaker Data API.

Notice in the screenshot I have a test record to delete.

Click the minus icon and a dialog will pop open to confirm deletion of the contact. Click Yes to delete the record.

As you can see, the record is now gone. Let’s continue to the double square plus icon used for duplicate.

This script is setup to work only in the context for Contacts. It has to do other things, but the basic duplicate code could be made into a utility script called as a subscript. Feel free to take the challenge and try that on your own. 

Starting at the top, there is a variable for contactInfo which I will use later in the script. It should look very familiar! It is used in the Contact – Update Record – Execute FM Data API script, but missing the record id. We need to use the new record id when duplicating. Also, notice the word Copy in front of the first name? This will help show it was duplicated.

Notice the json at line 15 that will be sent to the Execute FileMaker Data API step. The action has been set to duplicate and its using the recordId from the record we are duplicating.

Once the record is duplicated, the newRecordId is parsed out from the response on line 37. It is, then, set back into the contactInfo on line 40. Finally, it runs the Contact – Create / Edit – Setup { json } script, so any changes made in the card window are sent to the correct record.

Here is what happens when you click the duplicate icon:

Next, let’s change the name and email as seen below.

Finally, the result when when you click Save.

Now, you are able to create, update, delete, and duplicate with the Execute FileMaker Data API script step in Claris FileMaker 21. Hope you enjoyed this blog series and have a great rest of the week.