![claris filemaker oauth emails.](/img/containers/main/article/2024/09/claris-filemaker-oauth-emails.png/b27763b848725f6e758c786615e5b4b1.png)
The Execute FileMaker Data API (EDAPI) script step can now execute write operations. In the past, this step was only capable of doing read operations, but now you can use this script step to make changes to your data. EDAPI will package the result as a JSON object in a given variable, using JSON objects for smoother integrations with web viewers and JavaScript.
This single script step can make changes to your data without the need for any other script steps. It can also be called regardless of what context you're currently in. It can access records from anywhere in your file, all while staying in one layout. EDAPI is helpful because of the result's JSON format. This allows for more seamless interaction with web viewers, JavaScript, and more. Despite what you may think from its name, EDAPI does not actually use the FileMaker Data API. It only mimics its behavior. Because of this you can run it on a local file and you do not need to have the Data API option enabled on the server.
![youtube-preview](/img/http/vi/IV87I2EuI7k/maxresdefault.jpg/e6f45c84a30ca46e1c527eb18aff571f.jpg)
Create
JSONSetElement ( "{}" ; [ "action" ; "create" ; JSONString ] ; [ "fieldData" ; "{ \"firstName\" : \"John\" , \"lastName\" : \"Doe\" }" ; JSONObject ] ; [ "layouts" ; "Example" ; JSONString ] )
When using EDAPI to create records, you just need to specify the layout in the context of the table you're making a record of and the fields for the new record that you want to fill in. Make sure to list all the fields you want to fill in as a JSON object. Upon successful creation, it will return the ID of the newly created record.
{ "messages" : [ { "code" : "0", "message" : "OK" } ], "response" : { "modId" : "0", "recordId" : "175" } }
Update
JSONSetElement ( "{}" ; [ "action" ; "update" ; JSONString ] ; [ "fieldData" ; "{ \"firstName\" : \"Jane\" , \"lastName\" : \"Doe\" }" ; JSONObject ] ; [ "layouts" ; "Example" ; JSONString ] ; [ "recordId" ; "176" ; JSONString ] )
When using EDAPI to update a record, you have to specify the specific record you want to change through its unique recordId, as well as the fields you want to change and their new values. If the record was updated successfully, it will return the modId, which is a count of how many times that record has been updated.
{ "messages" : [ { "code" : "0", "message" : "OK" } ], "response" : { "modId" : "1" } }
Delete
JSONSetElement ( "{}" ; [ "action" ; "delete" ; JSONString ] ; [ "layouts" ; "Example" ; JSONString ] ; [ "recordId" ; "176" ; JSONString ] )
Deleting a record only requires the layout of that context and the id of the record to be deleted. Once the record is deleted, it does not return anything.
{ "messages" : [ { "code" : "0", "message" : "OK" } ], "response" : {} }
Duplicate
JSONSetElement ( "{}" ; [ "action" ; "duplicate" ; JSONString ] ; [ "layouts" ; "Example" ; JSONString ] ; [ "recordId" ; "131" ; JSONString ] )
The setup for delete and duplicate are the exact same. All you need for both is the layout in that context and the recordId of the record you want to delete/duplicate. Duplicating will return the recordId of the newly created record.
{ "messages" : [ { "code" : "0", "message" : "OK" } ], "response" : { "modId" : "0", "recordId" : "177" } }
Metadata
The metaData action can be used to return metadata on tables and layouts in your application.
JSONSetElement ( "{}" ; [ "action" ; "metaData" ; JSONString ] ; [ "tables" ; "EXAMPLE" ; JSONString ] )
All that's required to retrieve metadata is the table you want the information from. If you enter in a specific table, it will show all the fields for that table. If you leave "tables" blank, it will instead list the names of all the tables in the file and their base tables. The same logic applies to layouts. Instead of "tables", you can use "layouts". If you leave it blank, it will list all of the layouts in the file.
{ "messages" : [ { "code" : "0", "message" : "OK" } ], "response" : { "baseTable" : "EXAMPLE", "fieldMetaData" : [ { "autoEnter" : true, "fourDigitYear" : false, "global" : false, "maxCharacters" : 0, "maxRepeat" : 1, "name" : "__kptID", "notEmpty" : true, "numeric" : false, "repetitionEnd" : 1, "repetitionStart" : 1, "result" : "text", "timeOfDay" : false, "type" : "normal" }, { "autoEnter" : false, "fourDigitYear" : false, "global" : false, "maxCharacters" : 0, "maxRepeat" : 1, "name" : "Name", "notEmpty" : false, "numeric" : false, "repetitionEnd" : 1, "repetitionStart" : 1, "result" : "text", "timeOfDay" : false, "type" : "normal" }, { "autoEnter" : false, "fourDigitYear" : false, "global" : false, "maxCharacters" : 0, "maxRepeat" : 1, "name" : "PhoneNumber", "notEmpty" : false, "numeric" : false, "repetitionEnd" : 1, "repetitionStart" : 1, "result" : "number", "timeOfDay" : false, "type" : "normal" }, { "autoEnter" : false, "fourDigitYear" : false, "global" : false, "maxCharacters" : 0, "maxRepeat" : 1, "name" : "Role", "notEmpty" : false, "numeric" : false, "repetitionEnd" : 1, "repetitionStart" : 1, "result" : "text", "timeOfDay" : false, "type" : "normal" } ], "portalMetaData" : {} } }
Conclusion
The new write operations for Execute FileMaker Data API are a great feature to improve your solution's communication with other sources that also use JSON. If you have any questions concerning this script step or anything else in FileMaker, contact us and we would be happy to help!
Did you know we are an authorized reseller for Claris FileMaker Licensing?
Contact us to discuss upgrading your Claris FileMaker software.
Download the Write Operations for Execute FileMaker Data API File
Please complete the form below to download your FREE FileMaker file.