Handling Events for INSERT, UPDATE and DELETE Operations

When writing an event-handling function for a replication, you often need to consider which type of operation (INSERT, UPDATE, DELETE) is being performed during the replication. In your replication script,  use the record's OperationType property to identify the type of operation being performed, as in the following VB.NET example.

Public Overrides Sub Record_onAfterMapping(recSource As IRecord, recTarget As IRecord, By Ref AbortRecord As Boolean)
  if (recSource.OperationType = enmOperationType.Update)
      AddLog(recSource.GetValueBefore(0), 0)
  End if
End Sub

Depending on the operation type, different functions for accessing source and target values are available.

INSERT Operations

Replication Types: Refresh (all records) and mirroring/synchronization (insert operations obtained from the transaction log)

Record Functions Available:

Source Record

Target Record

GetValueAfter(index)

GetValueAfter(index)

GetValueAfter(col)

GetValueAfter(col)

SetValueAfter(index, value)

SetValueAfter(index, value)

SetValueAfter(col, value)

SetValueAfter(col, value)

Note: Depending on the event function you are using, source or target record objects may not be available. Check the parameters for the event to see which objects you can use.

UPDATE Operations

Replication Types: Mirroring/synchronization (update operations obtained from the transaction log)

Record Functions Available:

Source Record

Target Record

GetValueBefore(index)*

GetValueBefore(index)*

GetValueBefore(col)*

GetValueBefore(col)*

SetValueBefore(col, value)**

SetValueBefore(col, value)**

SetValueBefore(index, value)**

SetValueBefore(index, value)**

GetValueAfter(index)

GetValueAfter(index)

GetValueAfter(col)

GetValueAfter(col)

SetValueAfter(index, value)

SetValueAfter(index, value)

SetValueAfter(col, value)

SetValueAfter(col, value)

* Values before an operation are not always available in the log and therefore these functions may return Null.

** These functions are rarely used.

Note: Depending on the event function you are using, source or target record objects may not be available. Check the parameters for the event to see which objects you can use.

DELETE Operations

Replication Types: Mirroring/synchronization (delete operations obtained from the transaction log)

Record Functions Available:

Source Record

Target Record

GetValueBefore(index)*

GetValueBefore(index)*

GetValueBefore(col)*

GetValueBefore(col)*

SetValueBefore(col, value)**

SetValueBefore(col, value)**

SetValueBefore(index, value)**

SetValueBefore(index, value)**

* Values before an operation are not always available in the log and therefore these functions may return Null.

** These functions are rarely used.

Note: Depending on the event function you are using, source or target record objects may not be available. Check the parameters for the event to see which objects you can use.

Related Topics
Global Script Functions

Replication Script Events

Replication Script Properties

IRecord Interface

Writing a Global Script

Writing a Replication Script

Writing Scripts with Visual Basic .NET