verified
Delete using BatchesLearn how to delete using batches (deleteBatch) in Salesforce Marketing Cloud (SFMC) with SSJS (server-side JavaScript). Code snippets include WSProxy methods.
Delete DataExtension records
var api = new Script.Util.WSProxy();
var batches = [
{
CustomerKey: "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
Keys: [
{
Name: "SubscriberKey",
Value: "S0M3-GU1D-K3Y-G03SR1G4T-H3R3"
}
]
}
];
var result = api.deleteBatch("DataExtensionObject", batches);
<script runat="server">
Platform.Load("core", "1");
var api = new Script.Util.WSProxy();
try {
var batches = [
{
CustomerKey: "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
Keys: [
{
Name: "SubscriberKey",
Value: "S0M3-GU1D-K3Y-G03SR1G4T-H3R3"
}
]
},
{
CustomerKey: "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
Keys: [
{
Name: "SubscriberKey",
Value: "S0M3-GU1D-K3Y-G03SR1G4T-H3R3"
}
]
}
];
var result = api.deleteBatch("DataExtensionObject", batches);
Write(Stringify(result));
} catch(error) {
Write(Stringify(error));
}
</script>
{
"Status": "OK",
"RequestID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
"Results": [
{
"ErrorMessage": null,
"KeyErrors": null,
"Object": {
"CustomerKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
"Properties": null,
"Name": null,
"Keys": [
{
"Name": "SubscriberKey",
"Value": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3"
}
],
"Type": null,
"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
},
"StatusCode": "OK",
"StatusMessage": "Deleted DataExtensionObject",
"OrdinalID": 0,
"ErrorCode": 0,
"RequestID": null,
"ConversationID": null,
"OverallStatusCode": null,
"RequestType": "Synchronous",
"ResultType": null,
"ResultDetailXML": null
},
{
"ErrorMessage": null,
"KeyErrors": null,
"Object": {
"CustomerKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
"Properties": null,
"Name": null,
"Keys": [
{
"Name": "SubscriberKey",
"Value": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3"
}
],
"Type": null,
"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
},
"StatusCode": "OK",
"StatusMessage": "Deleted DataExtensionObject",
"OrdinalID": 1,
"ErrorCode": 0,
"RequestID": null,
"ConversationID": null,
"OverallStatusCode": null,
"RequestType": "Synchronous",
"ResultType": null,
"ResultDetailXML": null
}
]
}
{
"Status": "Error",
"RequestID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
"Results": [
{
"ErrorMessage": "This Data Extension does not have any primary keys defined. Deletes cannot be performed.",
"KeyErrors": null,
"Object": {
"Name": null,
"Keys": [
{
"Name": "SubscriberKey",
"Value": "722214f7-50a1-44f1-b4ef-90c8462d2edc"
}
],
"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": "Error",
"StatusMessage": "Errors Occurred",
"OrdinalID": 0,
"ErrorCode": 2,
"RequestID": null,
"ConversationID": null,
"OverallStatusCode": null,
"RequestType": "Synchronous",
"ResultType": null,
"ResultDetailXML": null
}
]
}
WARNING
Deleting a non-existing record will still return status "OK".