Global Modules
  • 04 Sep 2024
  • 1 Minute to read
  • Dark
    Light

Global Modules

  • Dark
    Light

Article summary

General

Global modules can be used to write your own code that can be executed from any Expression or Execute Code Action.

Example: You could write a function that always returns the current date in a particular format. You can then re-use this function in Expression instead of having to write date formatting code multiple times.

All modules are written in  Visual Basic .NET; this makes it a very powerful tool, yet with a comparably easy syntax which is similiar to VBScript.

Managing Global Modules

There are two ways to manage global modules:

Management Service

You can connect to the Management Service of Mail & Deploy and click the Global Modules item in the main menu. This will provide you with a list of all global modules; you can edit or delete existing global modules or create new ones.

Report Designer

You can also edit global modules from the Report Designer by clicking the button in the main toolbar:


Button to manage Global Modules in the Report Designer

Functions and Subs

Every module is organized in Functions and Subs. A Sub is a code block that executes statements but does not return anything; a Function, on the other hand, is a code block that executes statements and does return something. A Sub that writes a text file could look like this:

Sub

Public Sub WriteToFile()
File.WriteAllText("C:\Temp\output.txt", "Hello World!")
End Sub

A Function that returns a string could look like this:

Function

Public Function GetText() As String
Return "Hello World!"
End Function

A function or sub in a module can also call another function or sub in a module:

Sub Calling Function

Public Function GetText() As String
Return "Hello World!"
End Function

Public Sub WriteTextFile()
File.WriteAllText("C:\Temp\output.txt", GetText())
End Sub

Parameters

Functions and Subs can take parameters which can then be used in the code:

Sub with Parameters

Public Sub WriteToFile(ByVal pPath As String, ByVal pContent As String)
File.WriteAllText(pPath, pContent)
End Sub

Examples

Formatting Dates

The following example is a Function that has no parameters and returns the current date with a specific format:

Date-Formatting Function

Public Function GetFormattedDate() As String
Return Date.Today.ToString("dd.MM.yyyy")
End Function


Was this article helpful?

What's Next