--- title: "Writing a Global Script" slug: "writing-a-global-script" updated: 2024-03-27T11:07:30Z published: 2024-03-27T11:07:30Z canonical: "skthelp.syniti.com/writing-a-global-script" --- > ## 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. # Writing a Global Script A global script is a shared module that defines a global class of functions or defines event handlers for global events. It can be used to define general user functions that need to be called from inside a replication script or an expression script. Global scripts can use or define the following sets of functions: - Microsoft C# Libraries Based on the scripting language selection in the Global Script Editor, you can use either C# or VB.NET to define scripts and functions for use in scripts. - Microsoft.VisualBasic Namespace Functions A .NET Framework Class Library that makes available Visual Basic 6 functions such as [Strings] Left, Mid, Right, Instr; [Math] Cos, Arc, Power and so on. - [Global Functions](/v1/docs/global-script-functions) Functions implemented as part of Syniti Replicate. - [Global Script Events](/v1/docs/global-script-events) Events that apply to all replications. - [User Functions](/v1/docs/writing-a-function-to-use-in-scripts-and-expressions) Functions that users define in the Global Script dialog typically for use from within Replication scripts. - [Create Table Rules or Functions](/v1/docs/writing-a-custom-create-table-rule) Functions used to customize how target tables are created. - [Field Mapping Rules or Functions](/v1/docs/writing-a-field-mapping-function) Functions used to determine how to map source and target columns when defining a replication. Use the Global Script Editor to write functions which are then typically used in [replication scripts](/v1/docs/writing-a-replication-script) and [expressions](/v1/docs/writing-an-expression-script). For example, you may have a conversion function that you use in several different replication scripts. Instead of repeating the conversion function for each replication script, it can be defined in a global script and then called from each replication script. 1. In the Management Center Metadata Explorer, select the metadata for which you want to write a global script. 2. From the right mouse button menu, choose **Global Script**. The Global Script Editor opens to display a stub for the script. The default script language is C#. ```plaintext using System; using System.Data; using DBMotoPublic; using DBMotoScript; namespace DBRS {     public class GlobalScript : IGlobalScript     {     }     public class MappingRule : IMappingRule     {     }     public class GlobalEvents : IGlobalEvents     {     } } ``` 3. In the GlobalScript class, declare functions as in the example below: ```plaintext public static DateTime DateConvert(int intDate)   int cyy;   int yyyy;   int mm;   int dd;     cyy = (int)(intDate / 10000);   mm = (int)((intDate - cyy * 10000) / 100);   dd = intDate % 100;   if (cyy < 100)       yyyy = 1900 + cyy;   else       yyyy = 2000 + (cyy % 100);   DateTime dc = new DateTime(yyyy, mm, dd);   return dc; } ``` 4. Define your functions. If the function is to be used in replication or expression scripts, add the keyword static after public: ```plaintext public static object GetQueryValue(IDbConnection objConnection, String strQuery) ``` 5. Declare any event handlers as in the following example for the Record_OnExecuteError event. Remember to specify the attribute GlobalEventAttribute. ```plaintext [GlobalEventsAttribute("Record_OnExecuteError", "Define a general event for the event EventName")]    public void MyErrorHandler(String sReplOrGroupName, DBMotoPublic.IRecord  recTarget, Exception e, ref Boolean bRetryExecute, ref int iSleep, int iIteration)        { } ``` 6. If you have added any libraries to the list of imports in the script, click ![](https://cdn.document360.io/ca09b4e9-1857-4c63-9f0e-1f25f166f447/Images/Documentation/ad453cf1-4db0-4ecd-be56-4ea501769fe0.png?sv=2026-02-06&spr=https&st=2026-11-17T19%3A21%3A39Z&se=2026-11-17T20%3A21%3A39Z&sr=b&sp=r&sig=fnrt2sGToMwVElXT4RU7w3htMs02UC%2BDHWPDnDAnaJ4%3D)![](https://cdn.document360.io/ca09b4e9-1857-4c63-9f0e-1f25f166f447/Images/Documentation/ScriptsEditorReferences.png?sv=2026-02-06&spr=https&st=2026-11-17T19%3A21%3A39Z&se=2026-11-17T20%3A21%3A39Z&sr=b&sp=r&sig=Cle6r1f%2B1ZVHLHfFYeqp8ae%2BAhceNC9WPHho7%2BMUGmU%3D) to open the References dialog and add the path to the library. 7. Use the Compile button ![](https://cdn.document360.io/ca09b4e9-1857-4c63-9f0e-1f25f166f447/Images/Documentation/CompileIcon.png?sv=2026-02-06&spr=https&st=2026-11-17T19%3A21%3A39Z&se=2026-11-17T20%3A21%3A39Z&sr=b&sp=r&sig=LdrabF4JGnvRUi3%2FADkACFxJLh%2FHDJMkAyT6SOu3p0Q%3D)![](https://cdn.document360.io/ca09b4e9-1857-4c63-9f0e-1f25f166f447/Images/Documentation/b52b261c-10a9-45ca-9b02-0999c0aea4b7.png?sv=2026-02-06&spr=https&st=2026-11-17T19%3A21%3A39Z&se=2026-11-17T20%3A21%3A39Z&sr=b&sp=r&sig=m5YESTm2S87%2BXNXLkedBW7%2FNJP%2B%2F1oiQ%2B4TF9KUvxcI%3D) to check your script syntax. Any script problems are displayed in a separate dialog. 8. Correct any syntax errors before attempting to run a replication. [Define mapping rules or functions](/v1/docs/writing-a-field-mapping-function) as needed to be used in mapping source and target fields. **Related Topics** [Global Script Functions](/v1/docs/global-script-functions) [Global Script Events](/v1/docs/global-script-events) [Writing a Function to use in Scripts and Expressions](/v1/docs/writing-a-function-to-use-in-scripts-and-expressions) [Global Script Function Examples](/v1/docs/vb-net-global-script-function-examples) [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) [IRecord Interface](/v1/docs/irecord-interface) [Writing a Replication Script](/v1/docs/writing-a-replication-script) [Writing Scripts with Visual Basic .NET](/v1/docs/writing-scripts)