Skip to main content
1 of 2

Create an upsert DE with SSJS

I am trying to use SSJS to retrieve the DE names of all DE's in a particular folder (folderid = 14273), and save them in an upsert DE (DE name = DEDE). The below script runs successfully in automation studio but when I check back DEDE, no rows are generated. I also tried testing by hardcoding the name of just 1 DE in the folder but that didn't work either.

The upsert DE has 2 fields, Name (primary key, text, max 300 characters) and CreatedDate (date, nullable)

<script runat="server">
Platform.Load("core", "1");

var api = new Script.Util.WSProxy();
var folderID = "14273"; 
var targetDE = DataExtension.Init("DEDE"); 

try {
    var req = api.retrieve("DataExtension", ["Name"], {
        Property: "CategoryID",
        SimpleOperator: "equals",
        Value: folderID
    });

    if (req.Results.length > 0) {
        for (var i = 0; i < req.Results.length; i++) {
            var deName = req.Results[i].Name;
            var data = [
                {
                    Name: deName
                }
            ];

            targetDE.Rows.Upsert(["Name"], data);
        }
    }
} catch (error) {
}