I am attempting to loop through data extension content to dynamically update and perform a query definition. Essentially, I'd like to update and run the same Query Definition synchronously using SSJS but the following code is not working. Is this even possible using the QD functions?
<script language="javascript" runat="server">
function queryUpdatePerform(qd, Query, UpdateType) {
qd = QueryDefinition.Init(qd);
var update_status = qd.Update({
QueryText: Query, TargetUpdateType: UpdateType
});
var perform_status = qd.Perform();
var status = "{Update:".concat(update_status).concat(", ").concat("Perform:").concat(perform_status).concat("}");
return status;
}
var QD_ExternalKey = "qd-externalkey";
var DE_ContentDetails_ExternalKey = "de-externalkey";
var contentDetailsDE = DataExtension.Init(DE_ContentDetails_ExternalKey);
var contentDetails = contentDetailsDE.Rows.Retrieve();
for (var i = 0; i < contentDetails.length; i++ ) {
var QueryLogic = contentDetails[i].QueryLogic;
var Query = "SELECT * FROM [SourceDE] WHERE EmailAddress IS NOT NULL AND ".concat(QueryLogic);
var status = "";
var ut = "";
if (i === 0) {
ut = "Overwrite";
status = queryUpdatePerform(QD_ExternalKey, Query, ut);
} else {
ut = "Update";
status = queryUpdatePerform(QD_ExternalKey, Query, ut);
}
}
</script>