--- title: "Global Script Functions" slug: "global-script-functions" updated: 2024-03-28T16:51:56Z published: 2024-03-28T16:51:56Z canonical: "skthelp.syniti.com/global-script-functions" --- > ## 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. # Global Script Functions The global functions for use in [Global scripts](/v1/docs/writing-a-global-script) are described below. If using these functions from a global script event, call them using the IGlobalScript class (e.g., IGlobalScript.AddLog). ## AddLog (String, enmLogMessageType) > [!NOTE] > Note > > this function supersedes AddLog(str As String, eType As Integer) Writes a log message in the DBMoto.log file. ### VB.NET syntax ```plaintext Public Shared Sub AddLog (str As String, eType As enmLogMessageType) ``` ### C# syntax ```plaintext public static void AddLog(string str, enmLogMessageType eType) ``` ### Parameters - str = message to log - eType = enumerator enmLogMessageType with the possible values: Information = 0, Warning = 1, Error = 2 ### Example [VB.NET syntax] ```plaintext AddLog ("The current record has been inserted", 0) ``` ### Example [C# syntax] ```plaintext AddLog("The current record has been inserted", 0) ``` ## AddLog (String, enmLogMessageType, Record, enmRecordImage) > [!NOTE] > Note > > this function supersedes AddLog(String, Int, Record, enmRecordImage) Writes a log message that includes the specified record information in the DBMoto.log file. ### VB.NET Syntax ```plaintext Public Shared Sub AddLog (str As String, eType As enmLogMessageType,   record As DBMotoPublic.IRecord, eRecordImage As enmRecordImage) ``` ### C# Syntax ```plaintext public static void AddLog(string str, enmLogMessageType  eType, DBMotoPublic.IRecord record,           enmRecordImage eRecordImage) ``` ### Parameters - str = message to log - eType = enumerator enmLogMessageType with the possible values: Information = 0, Warning = 1, Error = 2 - record = IRecord object to be logged along with the message - eRecordImage = enumerator enmRecordImage for type of record print required. The record image uses the Values After of the record if it comes from an INSERT operation, otherwise the Values Before. The parameter can have the value 1, 2 or 4: 1 = KeyValues-Print only the primary key columns values 2 = Image-Print the whole image of the record 4 = LogInfo-Print the log information (Transaction ID, Transaction Timestamp) ### Example [VB.NET syntax] ```plaintext Public Overrides Sub Record_onAfterMapping(recSource As IRecord, recTarget As IRecord,    ByRef AbortRecord As Boolean) Dim S as String AddLog("The current record has been inserted", 0, recSource, 4) End Sub ``` ## SendMail (subject, body) Sends an email using the SMTP settings defined in the [Mail tab](/v1/docs/replication-agent-options-dialog#mail) of the [Replication Agent Options dialog](/v1/docs/replication-agent-options-dialog). ### VB.NET syntax ```plaintext Public Shared Sub SendMail (sSubject As String, sMessageBody As String) ``` ### C# syntax ```plaintext public static void SendMail(string sSubject, string sMessageBody) ``` ### Parameters - sSubject = subject of the email - sMessageBody = body of the email ### Example [VB.NET syntax] ```plaintext SendMail ("Message from Syniti Replicate",   "An error occurred that requires intervention by the system administrator.") ``` ### Example [C# syntax] ```plaintext SendMail("Message from Syniti Replicate", ``` ```plaintext         "An error occurred that requires intervention by the system administrator.") ``` ## SendMail (subject, body, to) Sends an email using the SMTP settings defined in the [Mail tab](/v1/docs/replication-agent-options-dialog#mail) of the [Replication Agent Options dialog](/v1/docs/replication-agent-options-dialog). ### VB.NET syntax ```plaintext Public Shared Sub SendMail (sSubject As String, sMessageBody As String, sRcptTo As String) ``` ### C# syntax ```plaintext public static void SendMail(string sSubject, string sMessageBody, string sRcptTo) ``` ### Parameters - sSubject = subject of the email - sMessageBody = body of the email - sRcptTo = the email address of the intended recipient ### Example [VB.NET syntax] ```plaintext SendMail ("Message from Syniti Replicate",          "An error occurred that requires intervention by the system administrator.",   "somebody@company.com") ``` ### Example [C# syntax] ```plaintext SendMail("Message from Syniti Replicate",  "An error occurred that requires intervention by the system administrator.",  "somebody@company.com") ``` ## SendMail (sSubject, sMessageBody, sSMTPServer, sSMTPPort, sRcptFrom, sRcptTo, bAuthentication, sUser, sPassword, bUseSSL) Sends an email using the parameters defined when the function is called. When parameters are not passed, the Mail settings in the [Replication Agent Options dialog](/v1/docs/replication-agent-options-dialog) will be used instead. ### VB.NET syntax ```plaintext Public Shared Sub SendMail (sSubject As String, sMessageBody As String,                            sSMTPServer As String, sRcptFrom As String, sRcptTo As String) ``` ### C# syntax ```plaintext public static void SendMail(string sSubject, string sMessageBody, string sSMTPServer,             string sRcptFrom, string sRcptTo) ``` ### Parameters - sSubject = subject of the email - sMessageBody = body of the email - sSMTPServer = the SMTP server for outgoing mail - sSMTPPort = the SMTP server port for outgoing mail - sRcptFrom = the email address from which you want to send the message - sRcptTo = the email address of the intended recipient. - bAuthentication = True if authentication should be used, otherwise False - sUser = If bAuthentication is True, provide a user ID. - sPassword = f bAuthentication is True, provide a password - bUseSSL = True if SSL (Secure Sockets Layer) for email encryption should be used, otherwise False. ### Example [VB.NET syntax] ```plaintext SendMail ("Message from Syniti Replicate",   "An error occurred that requires intervention by the system administrator.",          "www.smtp.com", "DBMoto Notification Agent", "somebody@company.com") ``` ### Example [C# syntax] ```plaintext SendMail("Message from Syniti Replicate",   "An error occurred that requires intervention by the system administrator.",          "www.smtp.com", "Syniti Replicate Notification Agent", "somebody@company.com") ``` ## GetRecordInfo(Record, enmRecordImage) Returns a string containing formatted information about the record. ### VB.NET syntax ```plaintext Public Shared Function GetRecordInfo (record As DBMotoPublic.IRecord, eRecordImage As enmRecordImage) As String ``` ### C# syntax ```plaintext public static string GetRecordInfo(DBMotoPublic.IRecord record, enmRecordImage eRecordImage) ``` ### Parameters - record = IRecord object to be logged along with the message - eRecordImage = enumerator enmRecordImage for type of record print required. The record image uses the Values After of the record if it comes from an INSERT operation, otherwise the Values Before. The parameter can have the value 1, 2 or 4: 1 = KeyValues - Print only the primary key columns values 2 = Image - Print the whole image of the record 4 = LogInfo - Print the log information (Transaction ID, Transaction Timestamp) ### Example [VB.NET syntax] ```plaintext Imports Microsoft.VisualBasic Imports DBMotoPublic Imports DBMotoScript Imports DBRS.GlobalScript Namespace DBRS    Public Class ReplicationScript : Inherits IReplicationScript Public Overrides Sub Record_onAfterMapping(recSource As IRecord, recTarget As IRecord,                                                  ByRef AbortRecord As Boolean)   Dim S as String = GetRecordInfo(recSource, enmRecordImage.KeyValues)          AddLog("The current record has been inserted: " + S, 0)       End Sub    End Class End Namespace ``` ### Example [C# syntax] ```plaintext using System; using System.Data; using DBMotoPublic; using DBMotoScript; namespace DBRS {    public class ReplicationScript : IReplicationScript    {       public override void Record_onAfterMapping(DBMotoPublic.IRecord recSource,                   DBMotoPublic.IRecord recTarget, ref bool AbortRecord)       {           string = GlobalScript.GetRecordInfo(recSource, enmRecordImage.KeyValues);           GlobalScript.AddLog("The current record has been inserted: " + s, 0);        }    } } ``` ## GetJSONRecordInfo All four variants of this function below are helper functions that can be useful when mapping a generic structured or unstructured data into a JSON column type. ## GetJSONRecordInfo(record,eRecordImage) Returns a string in JSON format. For example: ```plaintext { "FIELD1" = "Value1", "FIELD2" = "Value2", "FIELD3" = "Value3" } ``` Object names and values are picked up from the IRecord object (and use the fields based on the enmRecordImage parameter). ### VB.NET syntax ```plaintext Public Shared Function GetJSONRecordInfo(ByVal record As DBMotoPublic.IRecord, ByVal eRecordImage As enmRecordImage) As String ``` ### C# syntax ```plaintext public static string GetJSONRecordInfo(DBMotoPublic.IRecord record, enmRecordImage eRecordImage) ``` ## GetJSONRecordInfo(args) Returns a string in JSON format. For example: ```plaintext {  "FIELD1" = "Value1", "FIELD2" = "Value2", "FIELD3" = "Value3" } ``` Object names and values are picked from a list of generic . ### VB.NET syntax ```plaintext Public Shared Function GetJSONRecordInfo(ParamArray ByVal args() As Object) As String ``` ### C# syntax ```plaintext public static string GetJSONRecordInfo(params object[] args)   ``` ## GetJSONRecordInfo(T value) Returns the JSON format for a specific object of type T. This function can be used when the value passed is not a string value but something else (such as a DateTime, a GUID, etc.) ### VB.NET syntax ```plaintext Public Shared Function GetJSONRecordInfo(Of T)(ByVal value As T) As String ``` ### C# syntax ```plaintext public static string GetJSONRecordInfo(T value) ``` ## GetJSONRecordInfo T (jsonString) The inverse of the function above. Given a certain value in JSON string format, it parses back the string and returns the object (of type T) from which it was generated. ### VB.NET syntax ```plaintext Public Shared Function GetJSONRecordInfo(Of T)(ByVal jsonString As String) As T   ``` ### C# syntax ```plaintext public static T GetJSONRecordInfo(string jsonString)    ``` ## GetReceiversInUse Returns a list of receivers in use by the replications in a Syniti Replicate connection as a ReceiversInfo object. The definition of the ReceiverInfo class is given below. For more information on using this function, see Writing a Script to Determine Receiver Use. ### VB.NET syntax ```plaintext Public Shared Function GetReceiversInUse (ConnectionName As String, IsSource As Boolean,           OnlyActiveReplications As Boolean) As ReceiverInfo() ``` ### C# syntax ```plaintext public static ReceiverInfo[] GetReceiversInUse(string ConnectionName, bool IsSource, bool OnlyActiveReplications) ``` ### Parameters - ConnectionName = Name of the IBM Db2 for i connection for which to retrieve the receivers in use - IsSource = True if ConnectionName refers to a source connection, false otherwise - OnlyActiveReplications = If true, retrieve only receivers used by active (Enabled) replications, and skip the disabled ones ### Example [VB.NET syntax] ```plaintext Imports Microsoft.VisualBasic Imports DBMotoPublic Imports DBMotoScript Imports DBRS.GlobalScript Imports System.Data Namespace DBRS   Public Class ReplicationScript : Inherits IReplicationScript Public Overrides Sub LogReader_onBeforeMirroring(bSource as Boolean)          Dim arrReceivers As ReceiverInfo() = GetReceiversInUse ("AS400", True, True)   Dim recInfo As ReceiverInfo   For Each recInfo in arrReceivers AddLog("Receiver in use: " + recInfo.JournalLibrary + "." + recInfo.JournalName  +                      "/" + recInfo.ReceiverLibrary + "." + recInfo.ReceiverName, 0)   Next End Sub   End Class End Namespace ``` ### Example [C# syntax] ```plaintext using System; using System.Data; using DBMotoPublic; using DBMotoScript; namespace DBRS {   public class ReplicationScript : IReplicationScript   { public override void LogReader_onBeforeMirroring(bool bSource) {          ReceiverInfo[] arrReceivers = GlobalScript.GetReceiversInUse("AS400", true, true);          foreach (ReceiverInfo recInfo in arrReceivers)          { GlobalScript.AddLog("Receiver in use: " + recInfo.JournalLibrary + "." + recInfo.JournalName                                   + "/" + recInfo.ReceiverLibrary + "." + recInfo.ReceiverName, 0);          }        }    } } ``` ### Other This function returns a value of type ReceiverInfo. The definition for the class is below. ```plaintext Public Class ReceiverInfo Public JournalLibrary As String Public JournalName As String Public ReceiverLibrary As String Public ReceiverName As String End Class ``` **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) [IRecord Interface](/v1/docs/irecord-interface) [Writing a Global Script](/v1/docs/writing-a-global-script) [Writing a Replication Script](/v1/docs/writing-a-replication-script) [Writing Scripts with Visual Basic .NET](/v1/docs/writing-scripts-in-syniti-replicate)