0

I'm a bit new to SSJS so I'm having trouble understanding how I would go about this.

I've started by referencing this: https://sprignaturemoves.com/prune-rows-data-extension-ssjs/

I created two Data Extensions, one that stores the data on Keys I need to remove from another data extension. Both of these tables have an ID field. Here are the DE's I created, along with their fields: "DataExtensionToPrune" --> 1 field, "RowKey" the unique identifier (numeric, PK) "DEofRowKeys" --> "RowKey" (numeric, PK), "RowDate" date, "RowsDeleted" (numeric), "Duration" (text 50), "ProcessedFlag" numeric), "Action" (text50)

I have a total of 1,000 records in "DataExtensionToPrune" and 14 records in "DEofRowKeys", the behaviour I am expecting is that "DataExtensionToPrune" decreases to 986 records.

I created a script activity and ran it, but nothing happens. The status doesn't get updated at all.

<script runat="server">

Platform.Load("core", "1.1.1");

function pruneRows () {

  var DERowKeys = DataExtension.Init("DEofRowKeys");
  var DERowKeyRows = DERowKeys.Rows.Lookup(["ProcessedFlag"], [0], 50, "RowDate");

  var returnString = "";
  var totalDelCount = 0;

  for (var i in DERowKeyRows) {

     var RowKey = DERowKeyRows[i].RowKey;
     var RowDate = DERowKeyRows[i].RowDate;

     returnString += "<br>" + RowKey;
     returnString += ", " + RowDate;

     var delCount = 0;
     var action = "";
     var begin = (new Date()).getTime();

     var sl = DataExtension.Init("DataExtensionToPrune");

     try {

       delCount += sl.Rows.Remove(["RowKey"], [RowKey]);
       totalDelCount += delCount;
       action = "delete";           
       returnString += ", " + delCount;

     } catch (e) {

       action = "error";

     }

     var end = (new Date()).getTime();
     var duration = (end-begin).toString() + 'ms ';

     // update row as processed
     if (action != "error") {

        var updateCount = DERowKeys.Rows.Update({"ProcessedFlag":1,"RowsDeleted":delCount, "Duration":duration, "Action":action}, ["RowKey"], [RowKey]);

     }

  }

  returnString += "<br>total deleted in batch: " + totalDelCount;

  return returnString;
}

</script>

1 Answer 1

2

You're not running your pruneRows() function at all, just declaring it. Either before or after the function place this in your code:

Write(pruneRows());
2
  • I just had a face palm moment, that makes so much sense now, thank you so much!!!! Sep 1, 2020 at 13:35
  • Haha! Been there myself, many a time. You read what you think you've written, and not what you've actually written sometimes. I helps to get a second pair of eyes.
    – Macca
    Sep 2, 2020 at 0:48

You must log in to answer this question.

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