Update a Data Extension verified

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

Core

var name = "MyDataExtension";

var de = DataExtension.Init(name);

var attrs = {
    CustomerKey: "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
    CategoryID: 1234
};

var result = de.Update(attrs);
<script runat="server">

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

        var name = "MyDataExtension";

        var de = DataExtension.Init(name);

        var attrs = {
            CustomerKey: "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
            CategoryID: 1234
        };

        var result = de.Update(attrs);

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

        Write(Stringify(error));

    }	

</script>
"OK"

WSProxy

var customerKey = "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
    categoryId = 1234;

var config = {
    "CustomerKey": customerKey,
    "CategoryID": categoryId
};

var result = api.updateItem("DataExtension", config);
<script runat="server">

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

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

        var customerKey = "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
            categoryId = 1234;

        var config = {
            "CustomerKey": customerKey,
            "CategoryID": categoryId
        };

        var result = api.updateItem("DataExtension", config);

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

        Write(Stringify(error));
        
    }	

</script>
{
    "Status": "OK",
    "RequestID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
    "Results": [
        {
            "Object": {
                "CustomerKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
                "Name": null,
                "Description": null,
                "IsSendable": false,
                "IsTestable": false,
                "SendableDataExtensionField": null,
                "SendableSubscriberField": null,
                "Template": null,
                "DataRetentionPeriodLength": 0,
                "DataRetentionPeriodUnitOfMeasure": 0,
                "RowBasedRetention": false,
                "ResetRetentionPeriodOnImport": false,
                "DeleteAtEndOfRetentionPeriod": false,
                "RetainUntil": null,
                "Fields": null,
                "DataRetentionPeriod": "Days",
                "CategoryID": 1234,
                "Status": null,
                "Client": null,
                "PartnerKey": null,
                "PartnerProperties": null,
                "CreatedDate": "0001-01-01T00:00:00.000",
                "ModifiedDate": null,
                "ID": 0,
                "ObjectID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
                "Owner": null,
                "CorrelationID": null,
                "ObjectState": null,
                "IsPlatformObject": false
            },
            "UpdateResults": null,
            "ParentPropertyName": null,
            "StatusCode": "OK",
            "StatusMessage": "Data Extension updated.",
            "OrdinalID": 0,
            "ErrorCode": 0,
            "RequestID": null,
            "ConversationID": null,
            "OverallStatusCode": null,
            "RequestType": "Synchronous",
            "ResultType": null,
            "ResultDetailXML": null
        }
    ]
}

WARNING

CustomerKey is required in order to update a Data Extension, both in Core and WSProxy.

Reference

Ressources and references related to the current methods.

Official documentation
SOAP object

Last Updated: