Post sync scripts
Overview
Post sync scripts are written in CQL and can be added to the end of a sync to allow you to do more with your data, such as inserted retrieved values into a Cinchy table.

Parameters
For real time syncs that have a Cinchy Table as the target, @InsertedRecordIds() and @UpdatedRecordIds() can be used in post sync scripts to narrow the scope of an update to the Cinchy Ids of the records that were inserted or updated by the event. These functions accept the values as a comma separated list, to be used in an IN clause.
Example:
(
[Cinchy Id] IN (@InsertedRecordIds())
OR
[Cinchy Id] IN (@UpdatedRecordIds())
)
Real-time syncs run a script once for each batch
In a real-time sync, the worker reads messages in batches and runs the post sync script once for each batch, not once for each message. In the script, @CinchyId and the other parameters taken from the message (such as the aliases of the listener's fields) hold the value of one message only: the last one in the batch.
A script that sets a value on the row for @CinchyId therefore changes one row for each batch. It can look correct when you test with a few messages and miss rows when the volume rises and batches fill up.
To act on every record in a batch, use @InsertedRecordIds() and @UpdatedRecordIds() as shown above. If the script needs each message's own values, make each batch hold one message. See Run a batch of one message.
If a post sync script fails or times out, the whole batch fails. The batch isn't retried, and its messages are written to the worker's dead message log.
Example
This example takes you through a batch data sync using the Cinchy Table [Product].[Names Test]. This scenario uses the following API as the destination: https://cinchy.net/API/Product/LatestCinchyReleaseDate
When you run the batch job, it will check for updates in the source table. These updates trigger the REST API to fetch our defined value, which we can use in a post-sync script. In this example, the script will insert this value into a second table, [Product].[Response Table].
The following steps will walk you through how to use this functionality.
- Set up your data sync to a REST API. You can review the Source, Destination, and Sync Behaviour.

-
Under the Post Sync tab, input the CQL that takes the defined variable from the REST API and insert it into the [Product].[Response Test] table.
-
Add in your Permissions and click Save.
-
After you configure the sync, run the job. It will check for new data in the Name column on the [Product].[Names] table. When found, it will trigger the REST API to GET the “value” variable. The post sync script will take that value and INSERT it into the [Product].[Response Test] table.
