--- title: "IRecord Interface" slug: "irecord-interface" updated: 2024-10-17T15:01:13Z published: 2024-10-17T15:01:13Z canonical: "skthelp.syniti.com/irecord-interface" --- > ## Documentation Index > Fetch the complete documentation index at: https://skthelp.syniti.com/llms.txt > Use this file to discover all available pages before exploring further. # IRecord Interface Used as a parameter when writing scripts to handle certain [replication events](/v1/docs/replication-script-events) or the [Record_OnExecuteError global event](/v1/docs/global-script-events#recordonexecuteerror), this interface provides access to records identified for replication either via transaction logs/journals during mirroring and synchronization replications, or via mapped source table records during refresh replications. Using the Get and Set methods, you can access and/or modify column values. ## ColumnCount (Property) The number of columns in the IRecord object, that is, it returns the number of mapped columns (within the current replication) in the table to which the IRecord is related. ### VB.NET syntax ```plaintext Public ReadOnly Property ColumnCount As Integer ``` ### C# syntax ```plaintext public int ColumnCount { get; } ``` ### Example [VB.NET syntax] This example prints a message in the log to show how many mapped columns have been found before applying the mapping. ```plaintext Public Overrides Sub Record_onBeforeMapping(recSource As IRecord, ByRef AbortRecord As Boolean)    AddLog("Column Count = " & recSource.ColumnCount, 0) ``` ```plaintext End Sub ``` ### Example [C# syntax] This example prints a message in the log to show how many mapped columns have been found before applying the mapping. ```plaintext public override void Record_onBeforeMapping(IRecord recSource, ref bool AbortRecord) {   GlobalScript.AddLog("Column Count = " + recSource.ColumnCount, 0); } ``` ## OperationType (Property) A list of constants that define the type of SQL operation associated with the transaction represented in the record. This property is typically used when designing mirroring or synchronization replications which use a transaction log. It provides access to the transaction's SQL operation: INSERT, UPDATE, DELETE, CLEAR or Unknown. If setting up a refresh replication, the only operation type is INSERT. The datatype for this property is the enumerator [enmOperationType](/v1/docs/irecord-interface#enmoperationtype-enumerator). ### VB.NET syntax ```plaintext Public Property OperationType As enmOperationType ``` ### C# syntax ```plaintext public enmOperationType OperationType { get; set; } ``` ### Example [VB.NET syntax] The example below checks to see if the operation being performed is an update before proceeding to add the value before changes apply to the Syniti Replicate log. ```plaintext Public Overrides Sub Record_onAfterMapping(recSource As IRecord, recTarget As IRecord,                                           ByRef AbortRecord As Boolean)  if (recSource.OperationType = enmOperationType.Update)          AddLog(recSource.GetValueBefore(0), 0)  End if End Sub ``` ### Example [C# syntax] The example below checks to see if the operation being performed is an update before proceeding to add the value before changes apply to the Syniti Replicate log. ```plaintext public override void Record_onAfterMapping(DBMotoPublic.IRecord recSource, DBMotoPublic.IRecord recTarget,                                           ref bool AbortRecord) {     if (recSource.OperationType == enmOperationType.Update    {          GlobalScript.AddLog("" + recSource.GetValueBefore(0), 0);    } } ``` ## enmOperationType (Enumerator) The datatype for the [OperationType property](/v1/docs/irecord-interface#operationtype-property). | **Value** | **Name** | **Description** | | --- | --- | --- | | 0 | Unknown | Not typically used | | 1 | Insert | A SQL INSERT operation | | 2 | Update | A SQL UPDATE operation | | 3 | Delete | A SQL DELETE operation | | 4 | Clear | For Db2/400 only. All values will be cleared from the record. This operation type is supported for mirroring replications only. | | 5 | Internal | For internal use only. | ## IsSource (Property) This property returns True when the record object has been generated while replicating a transaction **from** a connection defined under the Source node in the Management Center (often referred to as a source connection) **to** a connection defined under the Target node in the Management Center (target connection). In other words, all records replicated in a refresh or mirroring replication have this property set to True. In synchronization, it is set to True if the direction of the replication is source to target; False otherwise. ### VB.NET syntax ```plaintext Public Property IsSource as Boolean ``` ### C# syntax ```plaintext public bool IsSource { get; set; } ``` ### Example [VB.NET syntax] This sample function is defined in a synchronization replication and skips (i.e., doesn't propagate to the target) any Delete operations performed on the source table. ```plaintext Public Overrides Sub Record_onBeforeExecute(recTarget As IRecord, ByRef AbortRecord As Boolean)    If (recTarget.IsSource And recTarget.OperationType = enmOperationType.Delete)  Then     ``` ```plaintext      AbortRecord = True   End If End Sub ``` ### Example [C# syntax] This sample function is defined in a synchronization replication and skips (i.e., doesn't propagate to the target) any Delete operations performed on the source table. ```plaintext public override void Record_onBeforeExecute(IRecord recTarget, ref bool AbortRecord) {  if ((recTarget.IsSource & recTarget.OperationType == enmOperationType.Delete)) {     AbortRecord = true;  } } ``` ## IsPrimaryKey Provides a way to determine if a field is a primary key or part of a primary key. ### VB.NET syntax ```plaintext Public Function IsPrimaryKey (Index As Integer) As Boolean Public Function IsPrimaryKey (ColumnName As String) As Boolean ``` ### C# syntax ```plaintext public bool IsPrimaryKey(int Index) public bool IsPrimaryKey(string ColumnName) ``` ### Parameters - Index: an integer that identifies the column for which you want to retrieve the primary key settings - ColumnName: a string representing the column name for which you want to retrieve the primary key settings ### Return value Returns true if the field is part of the primary key. ### Example [VB.NET syntax] ```plaintext Public Overrides Sub Record_onAfterMapping(recSource As IRecord, recTarget As IRecord,                                           ByRef AbortRecord As Boolean)   Dim T As Boolean   T=recSource.IsPrimaryKey(1)       AddLog("Is the second column a primary key? True or False:  " + T.ToString, 0) End Sub ``` ### Example [C# syntax] ```plaintext public override void Record_onAfterMapping(IRecord recSource, IRecord recTarget,                                           ref bool AbortRecord) {   bool T = false;   T = recSource.IsPrimaryKey(1);   GlobalScript.AddLog("Is the second column a primary key? True or False:  " + T.ToString, 0); } ``` ## GetValueBefore Returns the value of the column indicated in the record before modification. If the value is not available in the transaction log, this function returns Null. Use this function in mirroring/synchronization replications if you want to retrieve a prior source or target value when the transaction log reports an UPDATE or DELETE operation on a record. ### VB.NET syntax ```plaintext Public Function GetValueBefore (sColName As String) As Object Public Function GetValueBefore (iIndex As Integer) As Object ``` ### C# syntax ```plaintext public object GetValueBefore(string sColName) public object GetValueBefore(int iIndex) ``` ### Parameters - sColName: name of the column to be referred to. - iIndex: index of the column to be referred to. ### Example [VB.NET syntax] The example below checks to see if the operation being performed is a SQL UPDATE. If it is, the [AddLog](/v1/docs/global-script-functions#addlog-string-enmlogmessagetype) function is called to add the value of the first column (before any changes are applied) to the Syniti Replicate log. The column value is identified by calling GetValueBefore with an index of 0. ```plaintext Public Overrides Sub Record_onAfterMapping(recSource As IRecord, recTarget As IRecord,                                           ByRef AbortRecord As Boolean)   if (recSource.OperationType = enmOperationType.Update)           AddLog(recSource.GetValueBefore(0), 0)   End if End Sub ``` ### Example [C# syntax] The example below checks to see if the operation being performed is a SQL UPDATE. If it is, the [AddLog](/docs/Global_Script_Functions.htm#AddLog) function is called to add the value of the first column (before any changes are applied) to the Syniti Replicate log. The column value is identified by calling GetValueBefore with an index of 0. ```plaintext public override void Record_onAfterMapping(IRecord recSource, IRecord recTarget, ref bool AbortRecord) {   if ((recSource.OperationType == enmOperationType.Update)) {       GlobalScript.AddLog(recSource.GetValueBefore(0), 0);    } } ``` ## GetValueAfter Returns the value of the column indicated in the record after modification. Use this function in refresh and mirroring/synchronization replications if you want to retrieve a source or target value for an INSERT operation or when the transaction log reports an UPDATE operation on a record. ### VB.NET syntax ```plaintext Public Function GetValueAfter (sColName As String) As Object Public Function GetValueAfter (iIndex As Integer) As Object ``` ### C# syntax ```plaintext public object GetValueAfter(string sColName) public object GetValueAfter(int iIndex) ``` ### Parameters - sColName: name of the column to be referred to. - iIndex: index of the column to be referred to. ### Example [VB.NET syntax] The example below checks to see if the operation being performed is a SQL UPDATE. If it is, the [AddLog](/v1/docs/global-script-functions#addlog-string-enmlogmessagetype) function is called to add the value of the CUSTOMERID column (after any changes are applied) to the Syniti Replicate log. The column value is identified by calling GetValueAfter with the column name, and the resulting value is converted to a string. ```plaintext Public Overrides Sub Record_onAfterMapping(recSource As IRecord, recTarget As IRecord,                                           ByRef AbortRecord As Boolean)    if (recSource.OperationType = enmOperationType.Update)            AddLog("Value = " + recTarget.GetValueAfter("CUSTOMERID").ToString(), 0)    End if End Sub ``` ### Example [C# syntax] The example below checks to see if the operation being performed is a SQL UPDATE. If it is, the [AddLog](/v1/docs/global-script-functions#addlog-string-enmlogmessagetype) function is called to add the value of the CUSTOMERID column (after any changes are applied) to the Syniti Replicate log. The column value is identified by calling GetValueAfter with the column name, and the resulting value is converted to a string. ```plaintext public override void Record_onAfterMapping(IRecord recSource, IRecord recTarget, ref bool AbortRecord) {   if ((recSource.OperationType == enmOperationType.Update)) {       GlobalScript.AddLog("Value = " + recTarget.GetValueAfter("CUSTOMERID").ToString(), 0);       } } ``` ## SetValueBefore Sets the value of the column indicated in the record before modification. This is an unusual method to use, because setting a value in a record before changes apply may ultimately have no effect. The method is included primarily to provide a complete set of methods. ### VB.NET syntax ```plaintext Public Sub SetValueBefore (sColName As String, objValue As Object) Public Sub SetValueBefore (iIndex As Integer, objValue As Object) ``` ### C# syntax ```plaintext public void SetValueBefore(string sColName, object objValue) public void SetValueBefore(int iIndex, object objValue) ``` ### Parameters - sColName: name of the column to be referred to. - iIndex: index of the column to be referred to. - objValue: the field value to set. ### Example [VB.NET syntax] As mentioned above, it is unlikely that this method will be useful, so the example below demonstrates how to use the method in a fairly unrealistic way. It checks to see if the operation being performed is a SQL UPDATE. If it is, for each updated record, the value before (that is the value to search for in the target table) is set to the first 3 characters concatenated with a blank. The after value is set to the original before value. ```plaintext ' For each updated record, set the value before (that is the value to search into the target table) ' to the first 3 characters concatenated with a blank. Then set the after value to the original before value. Public Overrides Sub Record_onBeforeMapping(recSource As IRecord, ByRef AbortRecord As Boolean)   Dim obj As Object   If recSource.OperationType = enmOperationType.Update Then         obj = recSource.GetValueBefore(0)         if Not obj Is Nothing AND Not IsDBNull(obj) Then              recSource.SetValueBefore(0 , obj.Substring(0,3) + " ")              recSource.SetValueAfter(0 , obj)         End if   End If End Sub ``` ### Example [C# syntax] As mentioned above, it is unlikely that this method will be useful, so the example below demonstrates how to use the method in a fairly unrealistic way. It checks to see if the operation being performed is a SQL UPDATE. If it is, for each updated record, the value before (that is the value to search for in the target table) is set to the first 3 characters concatenated with a blank. The after value is set to the original before value. ```plaintext // For each updated record, set the value before (that is the value to search into the target table) // to the first 3 characters concatenated with a blank. Then set the after value to the original before value. public override void Record_onBeforeMapping(IRecord recSource, ref bool AbortRecord) {   object obj = null;   if (recSource.OperationType == enmOperationType.Update) {       obj = recSource.GetValueBefore(0);       if ((obj != null) & !Information.IsDBNull(obj)) {           recSource.SetValueBefore(0, obj.Substring(0, 3) + " ");           recSource.SetValueAfter(0, obj);       }    } } ``` ## SetValueAfter Sets the value of the column indicated in the record after modification. Use this function in refresh and mirroring/synchronization replications if you want to change a source or target value for an INSERT operation or change a value when the transaction log reports an UPDATE operation on a record. ### VB.NET syntax ```plaintext Public Sub SetValueAfter (sColName As String, objValue As Object) Public Sub SetValueAfter (iIndex As Integer, objValue As Object) ``` ### C# syntax ```plaintext public void SetValueAfter(string sColName, object objValue) public void SetValueAfter(int iIndex, object objValue) ``` ### Parameters - sColName: name of the column to be referred to. - iIndex: index of the column to be referred to. - objValue: the field value to set. ### Example [VB.NET syntax] The example below checks to see if the operation being performed is a SQL UPDATE. Then, for each update, it replicates the value of the CITY column in uppercase. ```plaintext ' For each update, replicate the value of the column CITY in uppercase. Public Overrides Sub Record_onAfterMapping(recSource As IRecord, recTarget As IRecord, ByRef AbortRecord As Boolean)    Dim obj As Object    If recSource.OperationType = enmOperationType.Update Then           obj = recTarget.GetValueAfter("CITY")           if Not obj Is Nothing AND Not IsDBNull(obj) Then                recTarget.SetValueAfter("CITY", recTarget.GetValueAfter("CITY").ToUpper)           End if    End If End Sub ``` ### Example [C# syntax] The example below checks to see if the operation being performed is a SQL UPDATE. Then, for each update, it replicates the value of the CITY column in uppercase. ```plaintext // For each update, replicate the value of the column CITY in uppercase. public override void Record_onAfterMapping(IRecord recSource, IRecord recTarget, ref bool AbortRecord) {    object obj = null;    if (recSource.OperationType == enmOperationType.Update) {        obj = recTarget.GetValueAfter("CITY");        if ((obj != null) & !Information.IsDBNull(obj)) {            recTarget.SetValueAfter("CITY", recTarget.GetValueAfter("CITY").ToUpper);        }    } } ``` ## GetLogValue Returns the value of the log field indicated. The parameter should be of type [enmLogFields](/v1/docs/irecord-interface#enmlogfields-enumerator). ### VB.NET syntax ```plaintext Public Function GetLogValue (eLogField As enmLogFields) As Object ``` ### C# syntax ```plaintext public object GetLogValue(enmLogFields eLogField) ``` ### Parameters - eLogField: An [enmLogFields](/v1/docs/irecord-interface#enmlogfields-enumerator) datatype, this is the name of the field to be referred to. ### Example [VB.NET syntax] The example below retrieves values from the [enmLogFields enumerator](/v1/docs/irecord-interface#enmlogfields-enumerator) and adds them to the Syniti Replicate log. ```plaintext Public Overrides Sub Record_onBeforeMapping(recSource As IRecord, ByRef AbortRecord As Boolean)   AddLog("TransactionID = " + recSource.GetLogValue(enmLogFields.TransactionID).ToString(), 0)   AddLog("TransactionTS = " + recSource.GetLogValue(enmLogFields.TransactionTS).ToString(), 0)   AddLog("UserID = " + recSource.GetLogValue(enmLogFields.UserID).ToString(), 0)   AddLog("RecordID = " + recSource.GetLogValue(enmLogFields.RecordID).ToString(), 0)   AddLog("ReceiverLibrary = " + recSource.GetLogValue(enmLogFields.ReceiverLibrary).ToString(), 0)   AddLog("ReceiverName = " + recSource.GetLogValue(enmLogFields.ReceiverName).ToString(), 0) End Sub ``` ### Example [C# syntax] The example below retrieves values from the [enmLogFields enumerator](/v1/docs/irecord-interface#enmlogfields-enumerator) and adds them to the Syniti Replicate log. ```plaintext public override void Record_onBeforeMapping(IRecord recSource, ref bool AbortRecord) {   GlobalScript.AddLog("TransactionID = " + recSource.GetLogValue(enmLogFields.TransactionID).ToString(), 0);   GlobalScript.AddLog("TransactionTS = " + recSource.GetLogValue(enmLogFields.TransactionTS).ToString(), 0);   GlobalScript.AddLog("UserID = " + recSource.GetLogValue(enmLogFields.UserID).ToString(), 0);   GlobalScript.AddLog("RecordID = " + recSource.GetLogValue(enmLogFields.RecordID).ToString(), 0);   GlobalScript.AddLog("ReceiverLibrary = " + recSource.GetLogValue(enmLogFields.ReceiverLibrary).ToString(), 0);   GlobalScript.AddLog("ReceiverName = " + recSource.GetLogValue(enmLogFields.ReceiverName).ToString(), 0); } ``` ## enmLogFields (Enumerator) The datatype for the [GetLogValue](/v1/docs/irecord-interface#getlogvalue) parameter. | **Value** | **Name** | **Description** | | --- | --- | --- | | 0 | TransactionID | The transaction ID for the record from the transaction log/journal | | 1 | TransactionTS | The transaction timestamp | | 2 | UserID | The User ID associated with the transaction | | 3 | RecordID | For Db2/400 this is mapped to the RRN. For Oracle, it is mapped to the Row ID and for SQL Server, the value is always Null. | | 4 | ReceiverLibrary | For Db2/400 only. The library containing the receiver for this transaction. | | 5 | ReceiverName | For Db2/400 only. The name of the receiver used for this transaction. | ## SetLogValue Sets a value in the log field indicated. It is strongly recommended not to modify the values of the enmLogFields enumerator because it is used during mirroring and synchronization replications by the Replication Agent. ### VB.NET syntax ```plaintext Public Sub SetLogValue (eLogField As enmLogFields, objValue As Object) ``` ### C# syntax ```plaintext public void SetLogValue(enmLogFields eLogField, object objValue) ``` ### Parameters - eLogField: name of the field to be referred to. - objValue: the field value to set. ## GetType Returns the .NET type associated with the field type. ### VB.NET syntax ```plaintext Public Function GetType (Index As Integer) As System.Type Public Function GetType (ColumnName As String) As System.Type ``` ### Parameters - Index: an integer that identifies the column for which you want to retrieve the type - ColumnName: a string representing the column name for which you want to retrieve the type ### Return Value Returns the System.Type associated with the column, identified either by index or by column name. ## GetDBType Returns the database type associated with the field type. ### VB.NET syntax ```plaintext Public Function GetDBType (Index As Integer) As String Public Function GetDBType (ColumnName As String) As String ``` ### C# syntax ```plaintext public string GetDBType(int Index) public string GetDBType(string ColumnName) ``` ### Parameters - Index: an integer that identifies the column for which you want to retrieve the type - ColumnName: a string representing the column name for which you want to retrieve the type ### Return value Returns the name of the field type associated with the column, identified either by index or by column name. ## GetPrecision Returns the field precision. ### VB.NET syntax ```plaintext Public Function GetPrecision (Index As Integer) As Short Public Function GetPrecision (ColumnName As String) As Short ``` ### C# syntax ```plaintext public short GetPrecision(int Index) public short GetPrecision(string ColumnName) ``` ### Parameters - Index: an integer that identifies the column for which you want to retrieve the precision - ColumnName: a string representing the column name for which you want to retrieve the precision ### Return value Returns the precision of the column identified either by index or by column name ## GetScale Returns the field scale. ### VB.NET syntax ```plaintext Public Function GetScale (Index As Integer) As Short Public Function GetScale (ColumnName As String) As Short ``` ### C# syntax ```plaintext public short GetScale(int Index) public short GetScale(string ColumnName) ``` ### Parameters - Index: an integer that identifies the column for which you want to retrieve the scale - ColumnName: a string representing the column name for which you want to retrieve the scale ### Return value Returns the scale of the column identified either by index or by column name. ## GetLength Returns the field defined size ### VB.NET syntax ```plaintext Public Function GetLength (Index As Integer) As Integer Public Function GetLength (ColumnName As String) As Integer ``` ### C# syntax ```plaintext public int GetLength(int Index) public int GetLength(string ColumnName) ``` ### Parameters - eLogField: name of the field to be referred to. - objValue: the field value to set. ### Return value Returns the defined size of the column identified either by index or by column name. ## GetName Returns the column name associated with the field index. ### VB.NET syntax ```plaintext Public Function GetName (Index As Integer) As String ``` ### C# syntax ```plaintext public string GetName(int Index) ``` ### Parameters - Index: an integer that identifies the column for which you want to retrieve the name ### Return Value Returns the name associated with the column, identified by index. ### Example [VB.NET Syntax] ```plaintext Public Overrides Sub Record_onAfterMapping(recSource As IRecord, recTarget As IRecord,                                           ByRef AbortRecord As Boolean)   Dim S As String   S=recSource.GetName(0)   AddLog("The first column name is:" + S, 0) End Sub ``` ### Example [C# Syntax] ```plaintext public override void Record_onAfterMapping(IRecord recSource, IRecord recTarget, ref bool AbortRecord) {   string S = null;   S = recSource.GetName(0);   GlobalScript.AddLog("The first column name is:" + S, 0); } ``` **Related Topics** [Replication Script Events](/v1/docs/replication-script-events) [Handling Events for INSERT, UPDATE and DELETE Operations](/v1/docs/handling-events-for-insert-update-and-delete-operations) [Replication Script Properties](/v1/docs/replication-script-properties) [Global Script Functions](/v1/docs/global-script-functions) [Writing a Replication Script](/v1/docs/writing-a-replication-script) [Writing a Global Script](/v1/docs/writing-a-replication-script) [Writing Scripts with Visual Basic .NET](/v1/docs/writing-scripts-in-syniti-replicate)