Custom Data Types

In Data Extensions, you can use both built-in types like string, int, etc., but also Custom Data Types which are types that you define.

Usage

For example, rather than adding properties to an auto policy such as driverName1, driverName2, driverLicense, driverLicense2, and then having to guess how many of each of these you will need, you could do the following:

  • First, create a custom data type called Driver by adding this to the configuration:

{
    "dataTypes": {
        "Driver": {
            "data": {
                "firstName": { "type": "string" },
                "lastName": { "type": "string" },
                "licenseNumber": { "type": "string", "maxLength: 20" },
                "licenseState": { "type": "string", "maxLength": 2 }
            }
        }
    }
}
  • Then, for your policy element (or any element) in the configuration for the auto product, declare a property that uses the type Driver in its extension data:

{
    "products": {
        "personalAuto": {
            "data": [
                "drivers": { "type": "Driver+" }
            ],
            "contents": "vehicle+"
        }
    }
}

Custom Data Inheritance

Custom data types can use inheritance, similar to how elements and accounts can use inheritance to keep related types simpler to manage. Common information is put in a base and the differences expressed with individual declarations.

For example, maybe you want to have two different types of people in your system, with the general “Person” having just names, but a “Driver” adding driver’s license information. You could do that as follows:

First, declare the Person type:

"Person": {
    "data": {
        "firstName": {
            "type": "string"
        },
        "lastName": {
            "type": "string"
        }
    }
}

And then extend Person with added properties in a Driver:

"Driver": {
    "extends": "Person",
    "data": {
        "licenseNumber": {
            "type": "string",
            "maxLength: 20"
        },
        "licenseState": {
            "type": "string",
            "maxLength": 2
        }
    }
}

Inheritance can be many levels deep. You could extend Driver to manage a CommercialDriver type:

"CommercialDriver": {
    "extends": "Driver",
    "data": {
        "stateQualificationExamDate": {
            "type":
            "date"
        },
    }
}

Validation

Each custom type will have its properties validated in the same way as for built-in types. Custom types are also available for inspection and validation using the Validation Plugin.