Skip to main content
2 of 2
confused 2 questions and answered incorrectly on both...need more coffee
Gortonington
  • 30.9k
  • 3
  • 27
  • 64

I would create one script to duplicate your data extension, you can use WSProxy to do this (Retrieve DE info call, Retrieve Fields call then Create DE call) and then create and perform query activities via SSJS to fill in the newly created data extension.

Simple example of the create then execute script for Query:

<script runat="server">
Platform.Load("Core","1.1") ;

var deName = {{yourTargetDEName}}

var queryName = {{yourQueryName}}

var queryDef = { Name : queryName,

CustomerKey : queryName,
TargetUpdateType : "Overwrite",
TargetType : "DE",

Target:{
Name: deName,
CustomerKey : deName
},
QueryText : "SELECT {{myField}} FROM {{mySourceDE}}"
};

var status = QueryDefinition.Add(queryDef);

sleep(3000); //Wait for 3 seconds
//This helps ensure creation is complete before attempting to execute

var qd = QueryDefinition.Init("myQueryDef");
var status = qd.Perform();


function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}
</script>
Gortonington
  • 30.9k
  • 3
  • 27
  • 64