verified
Update using BatchesLearn how to update using batches (updateBatch) in Salesforce Marketing Cloud (SFMC) with SSJS (server-side JavaScript). Code snippets include WSProxy methods.
Update DataExtension records
var api = new Script.Util.WSProxy();
var batches = [
{
CustomerKey: "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
Properties: [
{
Name: "SubscriberKey",
Value: "S0M3-GU1D-K3Y-G03SR1G4T-H3R3"
},
{
"Name": "EmailAddress",
"Value": "updated@mail.com"
}
]
}
];
var options = {
SaveOptions: [
{
'PropertyName': '*',
SaveAction: 'UpdateAdd'
}
]
};
var result = api.updateBatch("DataExtensionObject", batch, options);
<script runat="server">
Platform.Load("core", "1");
var api = new Script.Util.WSProxy();
try {
var batches = [
{
CustomerKey: "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
Properties: [
{
Name: "SubscriberKey",
Value: "S0M3-GU1D-K3Y-G03SR1G4T-H3R3"
},
{
"Name": "EmailAddress",
"Value": "updated1@mail.com"
}
]
},
{
CustomerKey: "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
Properties: [
{
Name: "SubscriberKey",
Value: "S0M3-GU1D-K3Y-G03SR1G4T-H3R3"
},
{
"Name": "EmailAddress",
"Value": "updated2@mail.com"
}
]
}
];
var options = {
SaveOptions: [
{
'PropertyName': '*',
SaveAction: 'UpdateAdd'
}
]
};
var result = api.updateBatch("DataExtensionObject", batches, options);
Write(Stringify(result));
} catch(error) {
Write(Stringify(error));
}
</script>
{
"Status": "OK",
"RequestID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
"Results": [
{
"ErrorMessage": null,
"KeyErrors": null,
"ValueErrors": null,
"Object": {
"Name": null,
"Keys": null,
"Type": null,
"Properties": [
{
"Name": "SubscriberKey",
"Value": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3"
},
{
"Name": "EmailAddress",
"Value": "updated1@mail.com"
}
],
"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
},
"UpdateResults": null,
"ParentPropertyName": null,
"StatusCode": "OK",
"StatusMessage": "Upserted DataExtensionObject",
"OrdinalID": 0,
"ErrorCode": 0,
"RequestID": null,
"ConversationID": null,
"OverallStatusCode": null,
"RequestType": "Synchronous",
"ResultType": null,
"ResultDetailXML": null
},
{
"ErrorMessage": null,
"KeyErrors": null,
"ValueErrors": null,
"Object": {
"Name": null,
"Keys": null,
"Type": null,
"Properties": [
{
"Name": "SubscriberKey",
"Value": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3"
},
{
"Name": "EmailAddress",
"Value": "updated2@mail.com"
}
],
"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
},
"UpdateResults": null,
"ParentPropertyName": null,
"StatusCode": "OK",
"StatusMessage": "Upserted DataExtensionObject",
"OrdinalID": 1,
"ErrorCode": 0,
"RequestID": null,
"ConversationID": null,
"OverallStatusCode": null,
"RequestType": "Synchronous",
"ResultType": null,
"ResultDetailXML": null
}
]
}
{
"Status": "Has Errors",
"RequestID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
"Results": [
{
"ErrorMessage": null,
"KeyErrors": null,
"ValueErrors": null,
"Object": {
"Name": null,
"Keys": null,
"Type": null,
"Properties": [
{
"Name": "SubscriberKey",
"Value": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3"
},
{
"Name": "EmailAddress",
"Value": "updated1@mail.com"
}
],
"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
},
"UpdateResults": null,
"ParentPropertyName": null,
"StatusCode": "OK",
"StatusMessage": "Upserted DataExtensionObject",
"OrdinalID": 0,
"ErrorCode": 0,
"RequestID": null,
"ConversationID": null,
"OverallStatusCode": null,
"RequestType": "Synchronous",
"ResultType": null,
"ResultDetailXML": null
},
{
"ErrorMessage": "",
"KeyErrors": null,
"ValueErrors": [
null
],
"Object": {
"CustomerKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
"Properties": [
{
"Name": "SubscriberKey",
"Value": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3"
},
{
"Name": "EmailAddress",
"Value": "updated2"
}
],
"Name": null,
"Keys": null,
"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
},
"UpdateResults": null,
"ParentPropertyName": null,
"StatusCode": "Error",
"StatusMessage": "Errors Occurred",
"OrdinalID": 1,
"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".