View All Blog Posts

Data Sync Automation Item Events

Requires Data Sync Release : 3.0.908+

We've been busy adding a new feature to Data Sync Project Automation that allows you to execute your own C# .NET Code during the synchronisation. This new feature is currently still in development build 3.0.908+ but available today in the latest beta build for you to try.

The events are as follows:-

  • BeforeAddItem
  • AfterAddItem
  • BeforeUpdateItem
  • AfterUpdateItem
  • BeforeDeleteItem
  • AfterDeleteItem

The before events allow you to cancel the operation by setting the Sync property false, you could then provide your own implementation.

The after events run after the item is committed and in certain providers will return the items identity in the target system. For example in Dynamics CRM this will return the Entity Guid ID value. In SQL Server the identity will return the value of SCOPE_IDENTITY on Insert.

We have also added some helper functions, for example the SQL Server provider now has ExecuteNonQuery and ExecuteScalar functions. This allows you to easily write back to the source record.

For example setting a field called LastSync to the current time.

public override void AfterUpdateItem(object sender, DataCompareItemInvariant item, object identity)
{
    DataSourceA.ExecuteNonQuery("UPDATE Northwind2 SET LastSync=? WHERE ProductID=?", DateTime.Now, item.Key);
}

This can actually be simplified via the UpdateSourceRow method.

public override void AfterUpdateItem(object sender, DataCompareItemInvariant item, object identity)
{
    DataSourceA.UpdateSourceRow("LastSync", DateTime.Now, item);
}

Not all providers support the automation events yet the providers with support for Automation Item events are.

  • SQL Server
  • OleDB Database
  • Odbc Database
  • Dynamics CRM 2011-2015 Entity Items (Batch off i.e. Batch=1 and Threads=1)
  • Podio Items, Members, Contacts
| Friday, May 8, 2015 |