I would like to create an Import Defination in marketing cloud using SSJS, where my source should be one dataExtenion and the traget should be another dataextension. I also want to start the ImportDefinition from my script, but I can't find how to do it.

Appreciate your help in advance.

  • Just out of curiosity, why create an import definition to get data from a DE to another ? You can achieve this using an SQL query inside of an Automation and either schedule your automation or fire it using an API call depending on your use case.. Dec 12, 2019 at 10:47
  • Yes, we can use SQL query for this. But in our scenario, for everyday deployment process, we are creating a copy of 15 new data extension and move the records from one data extension to another. So I thought like to automate this entire process. i am able create a copy of DE using SSJS but I am unable to find the Script to copy the Records. So thought to write script for import definition and just change the source and target DE. If I go with SQL approach, I need to create 15 SQL activity, which is time consuming. @RachidMamai
    – Ranjan
    Dec 12, 2019 at 10:57

1 Answer 1


Based on your comments, it sounds like the issue is not that you are tied to creating an import process, but that you want a way to fill in the 15 new DEs you create. I think your solution is to use queries, but you can create and perform these programatically via SSJS.

First thing I would make sure to save the names of the DEs you created inside of another DE for reference in the second script. I would then, as a second script, create and perform query activities to fill in these data extensions. You will likely need to create a For loop based off the DE holding your newly created DE names to ensure you create and execute accordingly.

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",

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){

Now there are things to consider while doing this in that you will have 15 Queries targeting the same source DE, so you may run into issues there - but with some adjustments and customization, you can get this going to automate your process.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .