When syncing records, you need to keep track of the timestamp that the record is modified. This should be a timestamp that is consistent regardless of the timezone of the user. All of the code samples use the Get ( CurrentTimeUTCMilliseconds ) function in FileMaker, and store this value in a number field.
You need three ( or four, if you're doing deletes ) fields in your tables for RESTfmSync to function :
- A unique ID field. Named "ID" in our sample file, this uses the Get ( UUID ) function to have a value that is unique regardless of context.
- A modified timestamp field. Called "ModifiedUTC" in the sample file, this is a number field.
- A sync timestamp field. Called "SyncUTC" in the sample file, this is a number field with an auto enter calculation.
- A deleted flag field. Called "RESTfmDeleteFlag" in our sample file, this is a number field.
- A sync client ID field. Called "RESTfmPersistentID" in our sample file, this is a text field.
The unique ID
A plain text field with no Auto Enter added. This will be used to store the unique ID ( from using Get ( UUID ) on the client ) that the client generates. So it doesn't need to auto enter at all. This must be a unique ID across all tables for the delete functionality to work, but could be a serial ID only if you weren't using the delete functionality.
Also note that if any other process creates records on the server that will then need to be pushed to clients, then this field will need a UUID set into it manually.
This field is used by the RESTfmSync script to store the most recent timestamp that the record was modified on a Local File and then synced. This field shouldn't be modified on the server, it should always contain the most recent users data.
This field keeps track of when a record was sent to the server by a user. So it's an auto enter calc, that any time this record is modified, it updates this value. This field is used as the search field in the "Pull" section of the sync for each client to find new records that they haven't seen before. It should be set as an auto enter calculation with the following value.
NOTE :: Other processes modifying these fields on the server directly
All of the documentation here assumes that you have a "dumb data file" on the server, so it's used only as a data store for the sync process. This is the simplest setup option, and there are lots of alternative setups, unfortunately too many to document them all here. However a simple caveat that if you want to make changes to the server via another user, or another script that runs on the server, you will need to take into consideration the mod and sync timestamps. These will need to be adjusted each time a record is modified AND you want that modification to be synchronised. So you might need either adjust the auto enter calc for BOTH fields, or potentially set these fields manually via script whenever a modification is made. Same for the ID field which will need a value set into it.
Alternatively if you want to make changes to the records and NOT have it sync, then you will need to change the auto enter calc to only update when via RESTfm, and not for local changes.
This field is only required if you're also managing deletes. It's a number field and is only ever set to 1 by the sync process, so it should by default be left empty.
This field optional field was added in RESTfmSync 4.0.0. It's to keep track of which client sent the record to the server, so that each client can exclude those records when pulling updates. If this isn't required, when you POST a record to the server, then sync again it will retrieve the same record from the server, even though it doesn't update its local copy. Adding this field an using the new version of RESTfmSync prevents the duplicate network traffic.