The DI# language implements several methods allowing for easy manipulation of the basic data types (string, int, etc.).
In DI#, every manipulated value has a data type which determines:
- the possible operations
- the available methods
- how the value can be displayed or compared
Understanding data types helps avoid common errors and write more robust and maintainable DI# code.
| Declaration | Type |
|---|---|
| string | Character string |
| int | Integer number |
| decimal | Decimal number |
| datetime | Date et time |
| bool | Boolean |
| timespan | Time span |
| datasource | Data source |
In order to be compatible with projects or relational tables that include nullable fields, some of the data types allow for null values. However, we strongly advise against using nullable types in your code, in order to reduce the risks of execution error.
Note: For certain data types (int, decimal, datetime) the DI# language allows values larger than what is supported by the database, meaning that it's possible to create a variable containing a value that cannot be stored in a database field of the same type as the variable. Refer to the projects and relational tables documentation to make sure of what the database limits are.
// Examples for each type |
Text (string)
A Unicode character string, each character is stored using 2 bytes. The string is delimited by quoting marks (").
Inside a string the symbol \ is used to escape when using special characters such as (\r) for carriage returns or (\n) for line breaks.
string | ||
|---|---|---|
| Property or method | Returned Type | Description |
| Length | int | Returns the number of characters in a string object. |
| Capitalize(...) | string | MyText.Capitalize() puts the 1st letter of the string in uppercase. MyText.Capitalize(true) puts the 1st letter of every word of the string in uppercase. |
| IndexOf(...) | int | MyText.IndexOf("find") returns the position of the 1st occurrence of the string passed as a parameter within the searched string. |
| LastIndexOf(...) | int | MyText.LastIndexOf("find") returns the position of the last occurrence of the string passed as a parameter within the searched string. |
| Left(n) | string | Returns the first n characters from the left of the string. Equivalent to MyText.Substring(0,n). |
| Right(n) | string | Returns the first n characters from the right of the string. Equivalent to MyText.Substring(MyText.Length-n,n). |
| Replace(...) | string | MyText.Replace("find","replace") returns a new string object where all occurrences of the 1st parameter string have been replaced with the 2nd parameter string. |
| Substring(...) | string | MyText.Substring(start, length) Extracts part of the original string, starting at the 1st parameter index, for the number of characters specified in the 2nd parameter. MyText.Substring(start) Extracts the characters from the original string, starting at a specific position, to the end of the string. |
| ToString(...) | string | Converts all characters from a string to lowercase. |
| ToLower() | string | Converts all characters from a string to lowercase. |
| ToUpper() | string | Converts all characters from a string to uppercase. |
| Trim() | string | Removes all leading and trailing spaces from the string. |
// Examples |
Note that based on the data type of the value returned by these methods and properties, you can chain other methods and properties.
[[ |
Integer (int)
A 32 bits integer number between -2 147 483 648 and 2 147 483 647.
int | ||
|---|---|---|
| Property or Method | Returned Type | Description |
| ToString() | string | Returns the value of the object as a character string. |
Decimal Number (decimal)
High precision floating point numbers (28-29 significant digits). Values range from (-7.9x1028)/(10028) to (7.9x1028)/(10028).
decimal | ||
|---|---|---|
| Property or Method | Returned Type | Description |
| ToString() | string | Returns the value of the object as a character string. |
Date and Time (datetime)
Specifies a date with the following formats:
• aaaa.MM.jj HH:mm:ss
• aaaa.MM.jj HH:mm
• aaaa.MM.jj
Note that it is not a string: a date must not be inside quotes. For the the time, it can be omited. The seconds can be omited too. If you don't specify the secondes, the value will be 0 seconds.
datetime | ||
|---|---|---|
| Property or Method | Returned Type | Description |
| AddYears(n) | DateTime | Adds n years to the original date. |
| AddMonths(n) | DateTime | Adds n months to the original date. |
| AddDays(n) | DateTime | Adds n days to the original date. |
| AddHours(n) | DateTime | Adds n hours to the original date. |
| AddMinutes(n) | DateTime | Adds n minutes to the original date. |
| AddSeconds(n) | DateTime | Adds n seconds to the original date. |
| DateDiff(d) | TimeSpan | Subtracts the d date from the original date and returns a timespan. |
| isDST() | bool | Returns true if the original date is using Daylight Savings Time, based on the culture of the execution context. |
| ToString(...) | String | Returns the value of the object as a character string. The result can be formatted using customization parameters. For more details: https://msdn.microsoft.com/fr-fr/library/az4se3k1(v=vs.110).aspx |
| Date | DateTime | Returns a new date composed only of the year/month/day of the original date. Hours/minutes/seconds are ignored. |
| Year | Int | Returns the year part of the original date. |
| Month | Int | Returns the month number (1 to 12) of the original date. |
| Day | Int | Returns the day of the month (1 to 31) of the original date. |
| DayOfYear | Int | Returns the day of the year (1 to 365) of the original date. |
| DayOfWeek | Int | Returns the day of the week (Sunday = 1, Saturday = 7) of the original date. |
| Hour | Int | Returns the hour part (0 to 23) of the original date. |
| Minute | Int | Returns the minute part (0 to 59) of the original date. |
| Second | Int | Returns the second part (0 to 59) of the original date. |
| Ticks | Int | Returns the number of ticks elapsed between January 1st, 0001 and the original date. 1 second = 10 000 000 ticks. |
[[ |
Boolean (bool)
A boolean value can be either TRUE or FALSE.
bool | ||
|---|---|---|
| Property or Method | Returned Type | Description |
| ToString() | string | Returns the character string "True" or "False". |
Date and Time (timespan)
Contrary to some other languages, timespan, in DI#, represents an amount of time, whether it's days, hours, minutes or seconds. This type exists primarily to perform operations datetime variables. Example: timespan t = date1 – date2 ;
Note: To directly assign a timespan variable, you must specify a value corresponding to a number of days (for example, 2.25 if you want to represent 2 days and 6 hours)
| timespan | ||
|---|---|---|
| Property or Method | Returned Type | Description |
| ToString() | string | Returns the value of the object as a character string. |
Data Source (datasource)
Any type of data listed in this grid, or any complex data type like arrays, lists, dictionaries, etc. (similar to the var data type in C#.
A DI# array is a container for one or more variables, associating keys with values in an ordered way. It can be used for simple lists, dictionaries, or more complex purposes like hash tables, queues and more. The value of an array element can be a single variable, a list or a multidimensional array. The data type of each element in an array can be fixed or dynamic (the same way List<datatype> works in any .NET language).
A typical array declaration in DI# looks like this:
{ value1, value2, value3 }
datasource myArray = { 1, 2, 3, "abc", "def" }; |
You can define a collection of named elements like this:
{ fieldName1 : value1, fieldName2 : value2, fieldName3 : value3 }
datasource myDictionary = { FristName : "John", LastName : "Smith", Age : 30 }; |
// An element's value is an expression, which itself can contain other expressions like in this example |
There are 2 ways to instantiate an array:
- Declare an array with fixed length: int a[10];
- Declare an array with a variable length: string b[] ;
string a[] = {"text1", "text2", "text3"}; |
// You can assign inital values when declaring the array.
int a[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
string b[] = { "texte 1", "test", "abc" };
Once an array is declared, it can only accept values of the type specified. Example: int a[10] will only accept integer values.
Query expressions can be used to fetch and transform information from any complex data source. These queries can retrieve, sort and filter an array (dictionary, list, etc.). Their goal is, starting from an array, to create a new data source that:
- Filters the original array (WHERE clause)
- Sorts the original array (ORDER BY clause)
- Extracts a specific property from items in the original array
- Deduplicates items (DISTINCT option)
| Query Element | Description |
|---|---|
| Select | Specifies the values to extract from the data source. Use the distinct option if you only wish to return unique values. |
| From | Identifies the data source to which the query is applied. |
| Where | Allows the filtering of results using inclusion or exclusion rules. |
| Order by | Sorts the data according to one or more fields, in ascending or descending order. Supported keywords: asc, ascending, desc, descending. |
Important Notes Although they are powerful, the data source query features come at a huge performance cost. If used incorrectly in a message, these queries can have an important impact on the speed at which messages are prepared. A single query placed in a message sent to a million contacts will have to be processed a million times. Don't hesitate to ask our support team or our analysts for advice when creating messages requiring this level of complexity. |
All these elements come together like this:
select identifier.proprerty1
from identifier in expression
where identifier.propriete1 = valeur
order by (identifier.propriete2 asc)
With :
- Expression: the structure from which the data will be extracted (array, collection, etc.).
- Identifier: the name of the variable that will be used to refer to the data source (in the select, where and order by clauses).
// Let's suppose the following data source: |