We have a script activity in automation studio to update the text of a query definition and target a new data extension. It currently selects all fields using the standard SELECT *, but we need to now list out all the fields specifically. As it is currently (after a script runs to get a value - @jobno - from an ampscript block):
<script runat=server>
Platform.Load("Core","1");
var qd = QueryDefinition.Init("OurQueryName");
var deName = Variable.GetValue("@jobno");
var status = qd.Update({
Name : "OurQueryName",
TargetUpdateType : "Overwrite",
TargetType : "DE",
Target : {
Name : (deName),
CustomerKey : (deName)
},
QueryText : "SELECT * FROM StaticDataExtension WHERE Job_Ref = '".concat(deName).concat("'")
});
qd.Perform();
</script>
This works perfectly but I need to basically loop through the fields in the DE, and stringify them, but my JS knowledge is patchy for how to loop and just stick them in a var (with a comma between them).
I'm using a loop elsewhere to retrieve DE fields using WSProxy for a DE duplication query:
<script runat="server">
Platform.Load('Core','1');
var i;
var fieldsFinal = []
for (i=0;i<fieldsResults.length;i++) {
var fieldsRow = fields.Results[i];
delete fieldsRow.ObjectID;
delete fieldsRow.StorageType;
if (fieldsRow.FieldType != "Text") {
delete fieldsRow.MaxLength;
}
delete fieldsRow.DataExtension;
/**multiple more delete functions to delete irrelevant attributes**/
fieldsFinal.push(fieldsRow);
}
</script>
This creates an array rather than a string, however the loop would give me exactly what I need - I'd just want to push the fieldsRow.Name for each row into a text string, separated by a comma - is this possible?