Use this editor to write a script that is run when a specific event occurs during replication. The script should consist of one or more functions selected from the drop-down lists at the top of the Editor. The drop-down list on the left displays the categories for which you can define an event handler. The Editor provides editing and formatting features that include automatic indentation, automatic coloring for syntax, numeric values, comments, "code folding", and keyboard shortcuts.
Category | Events | Event Type | Explanation |
|---|---|---|---|
Refresh | Available events apply to refresh replications only. | ||
LogReader | Available events apply only to mirroring and synchronization replications. onReceiverChanged applies only to replications involving System i/iSeries/AS400. | ||
Record | Available events apply to each record that is considered for replication. In the case of refresh replications, the events would apply to every record in the source/target table. In the case of mirroring and synchronization replications, the events would apply to records found in the transaction log. | ||
Replication | onConflict and onLateConflict should be used to resolve conflicts only for synchronization replications. |
The right drop-down list displays a list of appropriate events for which you can write a script. If no function was selected from the left side, the list remains empty.
The default Visual Basic template content of the Replication Script Editor looks as follows. However, it is possible to write the script using C# instead of Visual Basic by setting the scripting language in the Global Script Editor, accessible from the right mouse button menu on the metadata.
Imports Microsoft.VisualBasic
Imports DBMotoPublic
Imports DBMotoScript
Imports DBRS.GlobalScript
Namespace DBRS
Public Class ReplicationScript : Inherits IReplicationScript
End Class
End NamespaceWhen you choose an event to add to the script, it is always added directly below the ReplicationScript class as in the example below.
Imports Microsoft.VisualBasic
Imports DBMotoPublic
Imports DBMotoScript
Imports DBRS.GlobalScript
Namespace DBRS
Public Class ReplicationScript : Inherits IReplicationScript
Public Overrides Sub Record_onBeforeMapping(recSource As IRecord, ByRef AbortRecord As Boolean)
End Sub
End Class
End NamespaceAdd code to manage the event. You can include functions from other libraries in the script code, but be sure to add the library to the list of Imports, add the library location using the References dialog and set up a namespace for the library. You can access the References dialog by clicking
in the toolbar below the script.
Checks the script syntax. If you do not do this in the script editor, you may encounter errors when the replication is running. | |
![]() | Opens the Expression Generator |
![]() | Opens the References dialog so that you can add the location of any dlls that you are using from your script. You typically need to add dlls to the References dialog and to the script Imports when they do not belong to the default Microsoft .NET environment. |
Creates a comment for selected text | |
Uncomments selected text |
Editing and Formatting Features
Automatic indentation based on syntax
Colors to identify specific code elements: syntax in blue, numeric values in pink and comments in green
Code folding where sections of code can be collapsed or expanded for ease of reading. The editor displays a green bar on the left side with +/- signs. Click - to collapse a section of code, and click + to expand a section of code.
Common editing operations using keystroke combinations:
<SHIFT>Left, Right, Up, Down, Home, End, PageUp, PageDown | Move caret with selection |
<CTRL>C | Copy, paste, cut |
<CTRL>A | Select all text |
<CTRL>Z, <CTRL>Y | Undo/Redo |
Tab | Increase/decrease left indent of selected range |
<CTRL>Home | Go to first/last char of the text |
<SHIFT><CTRL>Home, <SHIFT><CTRL>End | Go to first/last char of the text with selection |
<CTRL>U | Convert selected text to upper/lower case |
<INSERT> | Switch between Insert Mode and Overwrite Mode |
<CTRL>Backspace | Remove word left/right |
<ALT>Mouse, <ALT><SHIFT>Up, Down, Right, Left | Enable column selection mode |
<ALT>Up | Move selected lines up/down |
<SHIFT>Del | Remove current line |
<ESC> | Close all opened tooltips, menus and hints |
<CTRL>Wheel | Zoom |
<CTRL>Up | Scroll Up/Down |
<CTRL>NumpadPlus, <CTRL>NumpadMinus | Zoom in, zoom out, no zoom |
Opening the Replication Script Editor
On the Replication Properties dialog General tab, check the Use Script option. Click Script to open the Replication Script Editor.
Related Topics
.png?sv=2022-11-02&spr=https&st=2026-02-13T04%3A47%3A44Z&se=2026-02-13T05%3A00%3A44Z&sr=c&sp=r&sig=d8UP2IgZWkNd%2FCKSS%2F3jqlnGKcBOUWPacm7hywd7Lsk%3D)