User Guide

Item Events

Project Automation Item Events allow you to intercept before and after an operation during the sync process.

You can cancel an operation by setting the Sync property to false in the Before event this is the same as unchecking the Sync flag in the comapre results window except this allows you to do it programatically.

  • BeforeAddItem(object sender, DataCompareItemInvariant item, object identity)
  • AfterAddItem(object sender, DataCompareItemInvariant item, object identity)
  • BeforeUpdateItem(object sender, DataCompareItemInvariant item, object identity)
  • AfterUpdateItem(object sender, DataCompareItemInvariant item, object identity)
  • BeforeDeleteItem(object sender, DataCompareItemInvariant item, object identity)
  • AfterDeleteItem(object sender, DataCompareItemInvariant item, object identity)

Note: Not all Data Connectors support Item Events

The item field contains details about the item to be either Added, Updated or Deleted.

  • Sync - If the item is to be synchronised.
  • Key - The Key value for the item
  • Row - A list of Columns for Update
  • SourceRow - A list of columns in the source row
  • GetTargetIdentifier() - Get the ID value for the Target Item

The identity field may contain the ID value of the target item this depends on the provider implementation.

Update Source System

One use-case is where you want to update the source system with the created ID value from the target, for example where in Dynamics CRM you want to add the Entity Guid to your source SQL Table whenever a new account is added. This can be done easily via the UpdateSourceRow helper function on the SQL Data Connector.

public override void AfterAddItem(object sender, DataCompareItemInvariant item, object identity)
{
	DataSourceA.UpdateSourceRow("CRM_ID", identity, item);		
}

Clear Sync flag from Source System

Another Example is using this to clear a Sync flag on the source SQL Table after it has been written to the target.

public override void AfterAddItem(object sender, DataCompareItemInvariant item, object identity)
{
	DataSourceA.ExecuteNonQuery(string.Format("UPDATE {0} SET [Sync]=0 WHERE [ID]=?", DataSourceA.SourceTable), item.Key);	
}