0

I am trying to create Query Definition using SSJS but its not working for me. my code as follows:

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

var queryDef = {
    Name : "Example Query Definition",
    CustomerKey : "myQueryDef",
    TargetUpdateType : "Overwrite",
    TargetType : "DE", 
    Target:{
    Name:"errorlog",
    CustomerKey : "errorlogkey"
    },
QueryText : "SELECT SubKey, Email, Name FROM [target DE] where FavoriteItemID=77"
};

var status = QueryDefinition.Add(queryDef);
var outDE=DataExtension.Init("errorlog"); // just to see the result
outDE.Rows.Add({message:status});
</script>

when i run this script using automation studio it runs but didn't create any Query :( also the status says 'ERROR' on the output..

please can some one help..

Thanks

1 Answer 1

2

When you are able to add your query manually in Automation Studio based on the definitions that you wrote above, then the code needs to work.

I have created a data extension named "errorlog" with the customer key of "errorlogkey". It has one field named "num". Then, I wrote my query based on that information.

At the end, the code below worked:

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

var queryDef = { Name : "Example Query Definition",

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

Target:{
Name:"errorlog",
CustomerKey : "errorlogkey"
},
QueryText : "SELECT SubscriberKey as num FROM EOL_test2"
};

var status = QueryDefinition.Add(queryDef);

var outDE=DataExtension.Init("errorlog"); // just to see the result

 outDE.Rows.Add(  {message:status});

</script>

For detailed information: http://emailpeer.com/creating-an-sql-query-in-ssjs/

1
  • thanks buddy working good, i made a stupid thing.. i put the same DE name on the Target and Sql Select statement so the TargetUpdateType should be 'Update' rather then 'Overwrite'.. Thanks for spending your time.. Commented Aug 1, 2018 at 8:15

You must log in to answer this question.

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