Programmable scripts

Introduction

Programmable scripts are essential to quality personalization of your email campaigns. Scripting allows you to automatically change the content of messages, depending on conditions defined in your scripting function. Through the use of scripts can vary, for example the salutation of your client, according of the data available in the database. Examples on this page will convince you that writing your own function is not at all difficult, and often they only need to modify the texts according to their needs.

Writing scripts

Scripting language is C#

Scripting uses C# language. In the most cases, however, sufficient to use "if" "else" conditions and assignment "=", the use of which is showed in the examples.

Name of script

Name of script must include the name of the script language as a prefix "cs" for example "cs:salutation". When it is inserted into the email content, script name must be enclosed in square brackets. For example: [[cs:salutation]]

Test of scripts

After writing the content of a function, by clicking the Test button, you can to verify syntax accuracy of the function. If the error message will be displayed, it is necessary to repair content of function and repeat the test.

Input data

Input data that you can use when writing your scripts come from the recipient's address and from the outbound campaign. You can use data from the current address row and from row of current campaign. (in both cases it is a System.Data.DataRow datatype from the C# definitions)

Text of the each field is accessible through the entries Address["FiledName"].ToString() method or Campaign["FieldName"].ToString() method, or by simple written using functions (methods) sAddress ("FieldName"), SCampaign("FieldName").

The list of available fields in the Address data row:
Subs_Email, Subs_Salutation, Subs_Gender, Subs_FirstName, Subs_MiddleName, Subs_LastName, Subs_Title, Subs_DateOfBirth, Subs_Occupation, Subs_Company, Subs_PhoneNumber, Subs_FaxNumber, Subs_MobileNumber, Subs_Street, Subs_City, Subs_PostalCode, Subs_State, Subs_Country, Subs_CountryCode, Subs_Text1, Subs_Text2, Subs_Text3, Subs_Status, Subs_BarCode, Subs_DateAdded, Subs_ReturnCount, Subs_ReturnBackDateReceived, Subs_ID, Subs_GUID

The list of available fields in the Campaign data row:
Camp_Name, Camp_Description, Camp_Number, Camp_DateCreated, Camp_Subject, Camp_FromName, Camp_FromEmail, Camp_EmailFilter, Camp_GUID, Camp_GroupId

Output data

The output of your function (script) is assigned into the "result" variable (type of: System.String). Content of variable "result" is inserted into the content of message instead of [[cs:ScriptName]] and replace the scripting tag.

Global variables

You can use global user defined variables using functions SetVariable("VariableName", Value) and GetVariable(""VariableName""). VariableName is type of System.String, Value is type of System.Object.

Special functions

You can attach files to email message dynamically by using the Attach() function. But be careful the file must be accesible from workstation, from which you sending emails. You can use the Run() function for the execution of batch file (.BAT, .EXE, .VBS, ..) which will be prepare the attachments.

//Example for use the Attach() function;
Attach("license.txt"); //Attach file using the file path "license.txt".

//Example for use the Run() function;
Run("Notepad.exe", "license.txt"); //Run "Notepad.exe" with using command line parameter "license.txt".

Examples of scripts

Example of script 1


Description: unless specified address (the "Subs_Salutation") then the result text will be the "Dear Customer", otherwise the result text will be set to the salutation + first name + last name.

if (SAddress("Subs_Salutation") == "")
{
    result = "Dear Customer";
}
else
{
    result = SAddress("Subs_Salutation") + " " + SAddress("Subs_FirstName") + " " + SAddress("Subs_LastName");
}

Example of script 2


Description: unless is specified name and surname then the result will be text "Dear Customer", otherwise the result will be the first name + surname.

if (SAddress("Subs_FirstName")+SAddress("Subs_LastName") == "")
{
    result = "Dear Customer";
}
else
{
    result = "Dear " + SAddress("Subs_FirstName") + " " + SAddress("Subs_LastName");
}

Example of script 3


Description: if the name is not specified, then the resulting text will be "Dear Customer", otherwise will be determined the sex of addressee.
                             The code will be treated three options:
                             Unknown sex (SAddress("Subs_Gender") == "")
                             male (SAddress("Subs_Gender") == "M")
                             and women, which could be verified by a comparison (SAddress("Subs_Gender") == "F")

if (SAddress("Subs_LastName") == "")
{
    result = "Dear Customer";
}
else
{
    if (SAddress("Subs_Gender") == "")
    {
        result = "Dear` " + SAddress("Subs_FirstName") + " " + SAddress("Subs_LastName");
    }
    else
        if (SAddress("Subs_Gender") == "M")
        {
            result = "Dear Mr. " + SAddress("Subs_LastName");
        }
        else
        {
            result = "Dear Mrs. " + SAddress("Subs_LastName");
        }
}

Example for the global user defined variables


// You may use user defined global variables

if (GetVariable("UserData") == null)
{
  int startIndex = 100;
  SetVariable("UserData", startIndex);
}
else
{
  int index = (int)GetVariable("UserData"); //You must retype Object to Integer
  index++;
  SetVariable("UserData", index);   
}
result = String.Format("Index is now: {0}", GetVariable("UserData"));