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.
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
EmailAddress. The application uses this field to establish a data relationship between a value specified by the
SendableSubscriberFieldproperty 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
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
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
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:
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
EmailAddress, you can use a simple loop to iterate through an array of Data Extension External Keys:
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:
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.