I'm trying to create a proof of concept data extension with one field for each unique value in a specific column of another data extension. I am intending to do this using a SSJS script run as part of an automation. I have written the following script:
var datasource = DataExtension.Init("CCH_POS_Requests_Log")
var data = datasource.Rows.Retrieve()
var codes = []
var uniques = []
for (var i = 0; i < data.length; i++) {
codes.push(data[i]["POS Type"])
}
for (var i = 0; i < codes.length; i++) {
if (indexOf(codes[i] === i)) {
uniques.push(codes[i])
}
}
var newDE = {
"CustomerKey": "createdbycode",
"Name": "Created Data Extension",
"Fields": []
};
for (var i = 0; i < uniques.length; i++) {
newDE.Fields.push({"Name": uniques[i]})
}
DataExtension.Add(newDE);
SFMC does not indicate any kind of syntax error within this code, and upon test running it in an automation the activity log indicated that it has run successfully, but it is not actually creating a data extension.