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

var newDE = {
    "CustomerKey": "createdbycode",
    "Name": "Created Data Extension",
    "Fields": []

for (var i = 0; i < uniques.length; i++) {
    newDE.Fields.push({"Name": uniques[i]})


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.


1 Answer 1


This line is not correct syntax:

if (indexOf(codes[i] === i)) {

Suggest changing to:

if (indexOf(codes[i]) === i) {

I'd suggest testing in a Cloudpage where you can utilise Write() to output your variables to troubleshoot. You can also use a try catch block to output (certain) errors.

You must log in to answer this question.

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