Update multiple non-sendable Data Extensions to be sendable

In order to programmatically update the settings of an existing Data Extension, we will interact with Salesforce Marketing Cloud’s SOAP Web Services API using WSProxy. Code snippets in this article will show you how to update a Data Extension, so that a non-sendable Data Extension is turned into a sendable Data Extension, but you can modify the script to update other properties of a Data Extension, like retention settings or field properties.

DataExtension object

The DataExtension object represents a data extension within an account. In order to turn a non-sendable Data Extension into a sendable one, we will have to update three of the object’s properties:

  • IsSendable (xsd:boolean) – Indicates whether you can use a data extension as part of an audience for a message send.
  • SendableDataExtensionField (DataExtensionField) – Indicates the field within a sendable data extension to use as an address as part of a send. Possible values include SubscriberID, CustomerKey, or EmailAddress. The application uses this field to establish a data relationship between a value specified by the SendableSubscriberField property and a value within a sendable data extension.
  • SendableSubscriberField (Attribute) – Indicates field to use as sending address. The application uses this field to establish a data relationship between a subscriber field and a value specified by the SendableDataExtensionField property.

To put it in simple words, we need to set the IsSendable value to true and establish which field in the data extension relates to the Subscriber table. If you do it from the UI, you can for example set it to “ContactKey relates to Subscribers on Subscriber Key” or “EmailAddress relates to Subscribers on Subscriber Key”. Here, we will do exactly the same thing, using the following structure:

SendableDataExtensionField relates to subscribers on SendableSubscriberField

Update Data Extension properties via WSProxy

We will use the updateItem WSProxy function to interact with the DataExtension object. Below script will identify a Data Extension by it’s External Key (CustomerKey), set the IsSendable field to true and establish the following send relationship: “email relates to Subscribers on Subscriber Key”, where email is the Data Extension field of type EmailAddress.

The possible values of the SendableSubscriberField include “Subscriber Key” or “Email Address”, depending on whether the Subscriber Key business rule has been turned on. This is the tricky part of this script, as upon retrieving the properties of a sendable Data Extension, the results will return SendableSubscriberField.Name as “_SubscriberKey”, but you actually need to use “Subscriber Key” in the update call.

Here’s the script that will update a single Data Extension:

<script runat="server">
Platform.Load("core","1.1.5");
try{
var prox = new Script.Util.WSProxy();
var CustomerKey = "xxxxx-xxxx-xxxx-xxxx", //Insert DE External Key
IsSendable = "true",
SendableDataExtensionField = {"Name": "email", "DataType": "EmailAddress"}, //Provide the name of the field used to establish a data relationship (SendableDataExtensionField relates to subscribers on SendableSubscriberField)
SendableSubscriberField = {"Name": "Subscriber Key"}; //Use "Subscriber Key" or "Email Address" depending on whether the SUBSCRIBER_KEY business rule has been turned on.
var res = prox.updateItem("DataExtension", {"CustomerKey":CustomerKey, "IsSendable":IsSendable, "SendableDataExtensionField":SendableDataExtensionField, "SendableSubscriberField":SendableSubscriberField});
Write(Stringify(res));
}catch(e){
Write(Stringify(e));
}
</script>

Update multiple Data Extensions in one call

We have two possible ways to go when it comes to updating multiple Data Extensions in one call.

If you’re working with a set of Data Extensions that have an identical field name and data type assigned to the field used in the send relationship, for example email field of type EmailAddress, you can use a simple loop to iterate through an array of Data Extension External Keys:

<script runat="server">
Platform.Load("core","1.1.5");
try{
var prox = new Script.Util.WSProxy();
var CustomerKey = []; //Create an array withh DE External Keys
var IsSendable = "true",
SendableDataExtensionField = {"Name": "email", "DataType": "EmailAddress"}, //Provide the name of the field used to establish a data relationship (SendableDataExtensionField relates to subscribers on SendableSubscriberField)
SendableSubscriberField = {"Name": "Subscriber Key"}; //Use "Subscriber Key" or "Email Address" depending on whether the SUBSCRIBER_KEY business rule has been turned on.
for(var i=0; i< CustomerKey.length; i++) {
var res = prox.updateItem("DataExtension", {"CustomerKey":CustomerKey[i], "IsSendable":IsSendable, "SendableDataExtensionField":SendableDataExtensionField, "SendableSubscriberField":SendableSubscriberField});
Write(Stringify(res) + "<br>");
}
}catch(e){
Write(Stringify(e));
}
</script>

If the field names vary across the Data Extensions, it’s best to use the updateBatch WSProxy function and define properties of each Data Extension separately:

<script runat="server">
Platform.Load("core","1.1.5");
try{
var prox = new Script.Util.WSProxy();
var de1 = {
"CustomerKey":"xxxx-xxxx-xxxx-xxxx-xxxx-xxxx",
"IsSendable":"true",
"SendableDataExtensionField":
{
"Name": "email",
"DataType": "EmailAddress"
},
"SendableSubscriberField":
{
"Name": "Subscriber Key"
}
};
var de2 = {
"CustomerKey":"xxxx-xxxx-xxxx-xxxx-xxxx-xxxx",
"IsSendable":"true",
"IsTestable":"true",
"SendableDataExtensionField":
{
"Name": "emailaddress",
"DataType": "EmailAddress"
},
"SendableSubscriberField":
{
"Name": "Subscriber Key"
}
};
var res = prox.updateBatch("DataExtension", [de1, de2]);
Write(Stringify(res));
}catch(e){
Write(Stringify(e));
}
</script>

Additional resources

If you would like to learn more about using WSProxy and the DataExtension object, I highly recommend reading Gortonington’s article, WSProxy to copy a data extension.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s