0

New to SSJS but based on what I've read, it looks like this could be possible. I am trying to write a script that will delete a row in a 'Secondary_DE' based on a defined 'Deleted' flag in a 'Primary_DE'.

For example: I want it to look in 'Primary_DE' for records that have a 'True' value in the field called 'Deleted' & then delete those records (based on their 'V_UUID' - present in both DE's) in the 'Secondary_DE'. AFTER it makes that initial deletion from 'Secondary_DE', I'd like it to delete the original record in 'Primary_DE'

I've referenced this question and am unsure what to put in the section starting with "for (var=" of the script (or if this is even the best approach):

<script runat="server">

Platform.Load("Core", "1");

     var deleteDE = DataExtension.Init("Secondary_DE EXTERNAL KEY");
     var data = deleteDE.Rows.Retrieve();

     for (var i=0; i < data.length; i++) {
       var subKey = data[i].SubscriberKey;

       var rowDelete = Platform.Function.DeleteData('Primary_DE',['Deleted'],[true]);

    };
</script>

Any help would be greatly appreciated, thanks!

1 Answer 1

0

You would need to retrieve all rows in the Primary_DE where it has the Deleted column equals true first. After that you can use the retrieved data result for the row deletion. Try something like this:

<script runat="server">

Platform.Load("Core", "1");

var masterDE = DataExtension.Init("ABCDE"); // Primary_DE external key
var filter = {Property:"Deleted",SimpleOperator:"equals",Value: "true"};

// Retrieve all rows in the Primary_DE where Deleted column equals true
var data = masterDE.Rows.Retrieve(filter);

for (var i=0; i < data.length; i++) {

       var V_UUID = data[i].V_UUID

       // Perform Row Deletion in the secondary DE
       var rowDelete = Platform.Function.DeleteData('Secondary_DE',['V_UUID'],[V_UUID]);

       // Perform Row Deletion in the primary DE
       var rowDelete = Platform.Function.DeleteData('Primary_DE',['V_UUID'],[V_UUID]);
}

</script>
1
  • thank you! This worked exactly how I needed it to. Really appreciate it
    – BeezB2020
    Commented Jan 5 at 3:50

You must log in to answer this question.

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