Created
July 10, 2018 14:46
-
-
Save samteezy/5f92d72d91a209a598108bc797a68735 to your computer and use it in GitHub Desktop.
SSJS to copy DEs (especially synchronized DEs)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %%[ | |
| 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