verified
Delete a Data Extension recordLearn how to delete Data Extension records (rows) in Salesforce Marketing Cloud (SFMC) with SSJS (server-side JavaScript). Code snippets include WSProxy, Core and Platform methods.
Platform
var name = "MyDataExtension";
var result = Platform.Function.DeleteDE(
name,
["EmailAddress"],
["example@mail.com"]
);
<script runat="server">
try {
var name = "MyDataExtension";
var result = Platform.Function.DeleteDE(
name,
["EmailAddress"],
["example@mail.com"]
);
Platform.Response.Write(Platform.Function.Stringify(result));
} catch(error) {
Platform.Response.Write(Platform.Function.Stringify(error));
}
</script>
null
Core
var customerKey = "S0M3-GU1D-K3Y-G03SR1G4T-H3R3";
var de = DataExtension.Init(customerKey);
var result = de.Rows.Remove(
["EmailAddress"],
["example@mail.com"]
);
<script runat="server">
Platform.Load("core", "1");
try {
var customerKey = "S0M3-GU1D-K3Y-G03SR1G4T-H3R3";
var de = DataExtension.Init(customerKey);
var result = de.Rows.Remove(
["EmailAddress"],
["example@mail.com"]
);
Write(Stringify(result));
} catch(error) {
Write(Stringify(error));
}
</script>
1
WSProxy
var api = new Script.Util.WSProxy();
var result = api.deleteItem("DataExtensionObject", {
CustomerKey: "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
Keys: [
{
Name: "SubscriberKey",
Value: "S0M3-GU1D-K3Y-G03SR1G4T-H3R3"
}
]
});
<script runat="server">
Platform.Load("core", "1");
var api = new Script.Util.WSProxy();
try {
var result = api.deleteItem("DataExtensionObject", {
CustomerKey: "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
Keys: [
{
Name: "SubscriberKey",
Value: "S0M3-GU1D-K3Y-G03SR1G4T-H3R3"
}
]
});
Write(Stringify(result));
} catch(error) {
Write(Stringify(error));
}
</script>
{
"Status": "OK",
"RequestID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
"Results": [
{
"ErrorMessage": null,
"KeyErrors": null,
"Object": {
"Name": null,
"Keys": [
{
"Name": "SubscriberKey",
"Value": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3"
}
],
"Type": null,
"Properties": null,
"Client": null,
"PartnerKey": null,
"PartnerProperties": null,
"CreatedDate": "0001-01-01T00:00:00.000",
"ModifiedDate": null,
"ID": 0,
"ObjectID": null,
"CustomerKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
"Owner": null,
"CorrelationID": null,
"ObjectState": null,
"IsPlatformObject": false
},
"StatusCode": "OK",
"StatusMessage": "Deleted DataExtensionObject",
"OrdinalID": 0,
"ErrorCode": 0,
"RequestID": null,
"ConversationID": null,
"OverallStatusCode": null,
"RequestType": "Synchronous",
"ResultType": null,
"ResultDetailXML": null
}
]
}
WARNING
WSProxy method only works when required fields' values are provided.
Reference
Ressources and references related to the current methods.
Official documentation
SOAP object