Retrieve a DataExtension field verified

Learn how to retrieve a Data Extension field in Salesforce Marketing Cloud (SFMC) with SSJS (server-side JavaScript). Code snippets include WSProxy and Core methods.

Core

var customerKey = "S0M3-GU1D-K3Y-G03SR1G4T-H3R3";

var de = DataExtension.Init(customerKey);

var result = de.Fields.Retrieve();
<script runat="server">

    Platform.Load("core", "1");

	try {

        var customerKey = "S0M3-GU1D-K3Y-G03SR1G4T-H3R3";

        var de = DataExtension.Init(customerKey);

        var result = de.Fields.Retrieve();

        Write(Stringify(result));
		
	} catch(error) {
        Write(Stringify(error));
    }	

</script>
[
    {
        "Name": "FirstName",
        "ObjectID": "42a5fbf1-fc56-4c73-93b9-315f5f597f2b",
        "FieldType": "Text",
        "IsPrimaryKey": false,
        "MaxLength": 50,
        "Ordinal": 0,
        "DefaultValue": "",
        "StorageType": "Plain"
    },
    {
        "Name": "LastName",
        "ObjectID": "b4b7a8e4-67cb-42a2-8152-dc8389668159",
        "FieldType": "Text",
        "IsPrimaryKey": false,
        "MaxLength": 80,
        "Ordinal": 1,
        "DefaultValue": "",
        "StorageType": "Plain"
    },
    {
        "Name": "EmailAddress",
        "ObjectID": "ff0f161f-9b01-4d3c-9fa1-e65dcfd694e5",
        "FieldType": "EmailAddress",
        "IsPrimaryKey": true,
        "MaxLength": 254,
        "Ordinal": 2,
        "DefaultValue": "",
        "StorageType": "Plain"
    }
]

WSProxy

var customerKey = "S0M3-GU1D-K3Y-G03SR1G4T-H3R3";

var cols = [
    "Name", 
    "MaxLength", 
    "IsRequired", 
    "FieldType", 
    "DefaultValue", 
    "Ordinal"
];

var result = api.retrieve("DataExtensionField", cols, {
    Property: "DataExtension.CustomerKey",
    SimpleOperator: "equals",
    Value: customerKey
});
<script runat="server">

    Platform.Load("core", "1");

    var api = new Script.Util.WSProxy();

	try {

        var customerKey = "S0M3-GU1D-K3Y-G03SR1G4T-H3R3";

        var cols = [
            "Name", 
            "MaxLength", 
            "IsRequired", 
            "FieldType", 
            "DefaultValue", 
            "Ordinal"
        ];

        var result = api.retrieve("DataExtensionField", cols, {
            Property: "DataExtension.CustomerKey",
            SimpleOperator: "equals",
            Value: customerKey
        });

        Write(Stringify(result));
		
	} catch(error) {
        Write(Stringify(error));
    }	

</script>
{
    "Status": "OK",
    "RequestID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
    "Results": [
        {
            "CustomerKey": null,
            "Name": "FirstName",
            "Ordinal": 0,
            "IsPrimaryKey": false,
            "FieldType": "Text",
            "DataExtension": null,
            "StorageType": "Unspecified",
            "DataType": null,
            "ValueType": "xsdstring",
            "PropertyType": "string",
            "IsCreatable": false,
            "IsUpdatable": false,
            "IsRetrievable": false,
            "IsQueryable": false,
            "IsFilterable": false,
            "IsPartnerProperty": false,
            "IsAccountProperty": false,
            "PartnerMap": null,
            "AttributeMaps": null,
            "Markups": null,
            "Precision": 0,
            "Scale": 0,
            "Label": null,
            "Description": null,
            "DefaultValue": "",
            "MinLength": 0,
            "MaxLength": 50,
            "MinValue": null,
            "MaxValue": null,
            "IsRequired": false,
            "IsViewable": false,
            "IsEditable": false,
            "IsNillable": false,
            "IsRestrictedPicklist": false,
            "PicklistItems": null,
            "IsSendTime": false,
            "DisplayOrder": 0,
            "References": null,
            "RelationshipName": null,
            "Status": null,
            "IsContextSpecific": false,
            "Client": null,
            "PartnerKey": null,
            "PartnerProperties": null,
            "CreatedDate": "0001-01-01T00:00:00.000",
            "ModifiedDate": null,
            "ID": 0,
            "ObjectID": null,
            "Owner": null,
            "CorrelationID": null,
            "ObjectState": null,
            "IsPlatformObject": false
        },
        {
            "CustomerKey": null,
            "Name": "LastName",
            "Ordinal": 1,
            "IsPrimaryKey": false,
            "FieldType": "Text",
            "DataExtension": null,
            "StorageType": "Unspecified",
            "DataType": null,
            "ValueType": "xsdstring",
            "PropertyType": "string",
            "IsCreatable": false,
            "IsUpdatable": false,
            "IsRetrievable": false,
            "IsQueryable": false,
            "IsFilterable": false,
            "IsPartnerProperty": false,
            "IsAccountProperty": false,
            "PartnerMap": null,
            "AttributeMaps": null,
            "Markups": null,
            "Precision": 0,
            "Scale": 0,
            "Label": null,
            "Description": null,
            "DefaultValue": "",
            "MinLength": 0,
            "MaxLength": 80,
            "MinValue": null,
            "MaxValue": null,
            "IsRequired": false,
            "IsViewable": false,
            "IsEditable": false,
            "IsNillable": false,
            "IsRestrictedPicklist": false,
            "PicklistItems": null,
            "IsSendTime": false,
            "DisplayOrder": 0,
            "References": null,
            "RelationshipName": null,
            "Status": null,
            "IsContextSpecific": false,
            "Client": null,
            "PartnerKey": null,
            "PartnerProperties": null,
            "CreatedDate": "0001-01-01T00:00:00.000",
            "ModifiedDate": null,
            "ID": 0,
            "ObjectID": null,
            "Owner": null,
            "CorrelationID": null,
            "ObjectState": null,
            "IsPlatformObject": false
        },
        {
            "CustomerKey": null,
            "Name": "EmailAddress",
            "Ordinal": 2,
            "IsPrimaryKey": false,
            "FieldType": "EmailAddress",
            "DataExtension": null,
            "StorageType": "Unspecified",
            "DataType": null,
            "ValueType": "xsdstring",
            "PropertyType": "string",
            "IsCreatable": false,
            "IsUpdatable": false,
            "IsRetrievable": false,
            "IsQueryable": false,
            "IsFilterable": false,
            "IsPartnerProperty": false,
            "IsAccountProperty": false,
            "PartnerMap": null,
            "AttributeMaps": null,
            "Markups": null,
            "Precision": 0,
            "Scale": 0,
            "Label": null,
            "Description": null,
            "DefaultValue": "",
            "MinLength": 0,
            "MaxLength": 254,
            "MinValue": null,
            "MaxValue": null,
            "IsRequired": true,
            "IsViewable": false,
            "IsEditable": false,
            "IsNillable": false,
            "IsRestrictedPicklist": false,
            "PicklistItems": null,
            "IsSendTime": false,
            "DisplayOrder": 0,
            "References": null,
            "RelationshipName": null,
            "Status": null,
            "IsContextSpecific": false,
            "Client": null,
            "PartnerKey": null,
            "PartnerProperties": null,
            "CreatedDate": "0001-01-01T00:00:00.000",
            "ModifiedDate": null,
            "ID": 0,
            "ObjectID": null,
            "Owner": null,
            "CorrelationID": null,
            "ObjectState": null,
            "IsPlatformObject": false
        }
    ],
    "HasMoreRows": false
}

Reference

Ressources and references related to the current methods.

Official documentation
Data Extension Fields
SOAP object

Last Updated: