Custom Data Types
Data extensions can be defined using custom data types in addition to built-in types such as string and int.
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
Driverby 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
policyelement (or any element) in the configuration for the auto product, declare a property that uses the typeDriverin its extension data:
{
"products": {
"personalAuto": {
"data": [
"drivers": { "type": "Driver+" }
],
"contents": "vehicle+"
}
}
}
As shown in the example above, you may use quantifiers such as + with custom data types. This includes the automatic creation quantifier !, which should be used if you want an item of your custom type to be created automatically. The platform does not infer the intent for automatic creation, even if all the custom type’s fields have default values.
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.