Adds a field to a data extension.
Syntax
Fields.Add(1)
Function Properties
| Ordinal | Type | Description |
|---|---|---|
1 |
Object | An object that specifies the properties of a data extension field. |
The field object can contain these properties.
| Name | Type | Description |
|---|---|---|
CustomerKey |
String | A unique ID for the field. |
DefaultValue |
String or Number | The default value that’s applied to the field if one isn’t provided when a row is added to the data extension. |
FieldType |
String | The type of field. Possible values: <ul><li>Boolean</li><li>Date</li><li>Decimal</li><li>EmailAddress</li><li>Locale</li><li>Number</li><li>Phone</li><li>Text</li></ul> |
IsPrimaryKey |
Boolean | Indicates whether the value of the field is used as a primary key. If true, the value is used as a primary key. |
IsRequired |
Boolean | Indicates whether a value must be provided for the field when a row is added to the data extension. If the value is true, the data extension field is required. |
MaxLength |
Integer | The maximum number of characters that can be specified in the value of a field. For a Text field, the value must be an integer that’s greater than 0 and less than or equal to 4000, and the default value is 50. For a Decimal field, this value specifies the maximum number of digits before and after the decimal point, and the maximum value is 29. |
Name |
String | Required. The name of the field. |
Ordinal |
Integer | The position of the field in the data extension. The ordinal value is used when displaying the data extension in Contact Builder. |
Scale |
Integer | The number of digits that can follow the decimal point in a Decimal field. The minimum value is 0 and the maximum value is 8. |
For more information, see Data Extensions Data Types in Email Studio.
Example
This code example adds a field to an existing data extension.
var de = DataExtension.Init('SSJSTest');
var newField = {
Name : "NewFieldV2",
CustomerKey : "CustomerKey",
FieldType : "Number",
IsRequired: true,
DefaultValue: "100"
};
var status = de.Fields.Add(newField);
For information about creating a data extension and adding fields, see DataExtension.Add.
See Also
- DataExtension.Add
- Salesforce Help: Data Extensions Data Types in Email Studio