Skip to content

Instantly share code, notes, and snippets.

@samteezy
Created July 10, 2018 14:46
Show Gist options
  • Select an option

  • Save samteezy/5f92d72d91a209a598108bc797a68735 to your computer and use it in GitHub Desktop.

Select an option

Save samteezy/5f92d72d91a209a598108bc797a68735 to your computer and use it in GitHub Desktop.
SSJS to copy DEs (especially synchronized DEs)
%%[
VAR @Result
]%%
<script runat="server">
Platform.Load("Core", "1.1.1");
try {
var DEtoCopy = DataExtension.Init("Contact_Salesforce");
var jsonArray = DEtoCopy.Fields.Retrieve();
for(var i = 0; i < jsonArray.length; i++) {
delete jsonArray[i]['ObjectID'];
jsonArray[i]['IsRequired'] = false;
if(jsonArray[i]['IsPrimaryKey'] == true)
jsonArray[i]['IsRequired'] = true;
if(jsonArray[i]['Name'] == '_ContactKey')
jsonArray[i]['Name'] = 'ContactKey';
if(jsonArray[i]['FieldType'] == 'Decimal') {
jsonArray[i]['FieldType'] = 'Text';
jsonArray[i]['MaxLength'] = 50;
};
};
var deObj = {"CustomerKey" : "SyncedContactsSalesforce","Name" : "SyncedContactsSalesforce","Fields" : jsonArray};
Write(Stringify(deObj));
var newDE = DataExtension.Add(deObj);
} catch (ex) {
Write("An error has occurred: " + Stringify(ex));
Write(" deObj: " + Stringify(deObj));
Variable.SetValue("@Result", Stringify(ex));
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment