0

SSJS to delete record from list runs, but no action I am getting similar error however in my case i am trying to delete the email from Auto supression list created in Email Studio Admin page.

    <script runat="server">
    Platform.Load("core", "1.1.1");
    var deleteDE = DataExtension.Init("Remove_Subscriber");
    var data = deleteDE.Rows.Retrieve();
    for (var i=0; i < data.length; i++) {
    var Emai = data[i].Email;
    var rowDelete = Platform.Function.DeleteData('Auto_Suppression_List',['Email Address'],[Emai]);
    var rows = Platform.Function.UpsertData("Remove_Subscriber",["Email"],[Emai],["Update"],[rowDelete]);
    };
    </script>

Below the Image of how my suppression list is configured.

Auto_Suppression_List

7
  • Can you share the error message you are seeing... If you are trying to run in a script activity, can you try to run this in CLoudPage and see what error message you get? Mar 30, 2023 at 11:51
  • 2
    There is a typo in your variable 'Email' var Email = data[i].Email Mar 30, 2023 at 11:52
  • 1
    @SwatiMishra - probably a typo, but at least a consistent one. Wherever this var i referenced, is always without 'l' Mar 30, 2023 at 18:03
  • Looks strange , because I tried the code exactly and it works for me Mar 31, 2023 at 5:43
  • When i Run this on landing page i am getting below error. Error Message: "Object expected: Retrieve" Description: "Jint.Native.JsException: Object expected: Retrieve Exception of type 'Jint.Native.JsException' was thrown. - from Jint "
    – syed Basha
    Mar 31, 2023 at 9:00

2 Answers 2

0

There are multiple levels here.

  1. The error message from your comment will point you exactly to the root cause, if you know how to interpret it and read docs.

Documentation says:

https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/ssjs_dataExtensionRowsRetrieve.html

Syntax is:

Rows.Retrieve(1)

You are calling Rows.Retrieve() without something in the bracket. The thing in the bracket is called an argument.

The documentation then says what this argument should be:

1 ... Specifies information to filter for the retrieve

So you cannot retrieve without a filter. You need to "put a filter in the bracket"

If you check the documentation example then you will see how such a filter should look:

{Property:"Age",SimpleOperator:"greaterThan",Value:20};

This is an object, which you'll recognize by the curly brackets (I am oversimplifying). The error message says that Retrieve cannot work due to an "Object expected".

So: The missing filter is exactly that "object expected" by the function from your error message.

Which confirms: You need to filter for something so that the retrieve returns data. You cannot just use the entire data extension.

==

2:

you could also just use Platform.Function.LookupRows if you already do everything else with Platform functions. I find it way simpler to write, and it works just with names of DEs, no need to "init", compose filters etc.

Server-side JavaScript - how lookup rows in data extension in Marketing cloud

Nice side effect: Saves you the performance-heavy loading of the "core" platform ( you can omit Platform.Load("core", "1.1.1"); ) as you no longer need anything from that library.

==

  1. if you need more than 2500 rows, the whole approach is flawed. There is an easier trick: Mark all records with a flag via upsert, then just run the deleteData function without for loops and lookups. See here:

Remove All Records with the Same email Domain in Suppresion list

3
  • I am not able to select the Auto Supression list to update the 'true' as toBeDeleted salesforce.stackexchange.com/questions/384663/…
    – syed Basha
    Apr 3, 2023 at 14:42
  • I think this is answered in the link: "for this to work, you have to create this query activity via the API, else you cannot target the autosuppression (UI limitation). Of course, you can also do this via import, but it's somewhat clumsy." Apr 3, 2023 at 15:43
  • For the below solution now i need to dynamically be able pull the values from DE. i.e "EMAIL_ADDRESS","SUPPRESSION_LIST" The value of SUPPRESSION_LIST would let me know from which list the deletion needs to perform. I tried below logic it fails. var data = deleteDE.Rows.Lookup(["STATUS"], [True], 2, ["EMAIL_ADDRESS","SUPPRESSION_LIST"]); for (var i=0; i < data.length; i++) { var Emai = data[i].EMAIL_ADDRESS; var SUPPRESSIONLIST1 = data[i].SUPPRESSION_LIST; var rowDelete = Platform.Function.DeleteData(['SUPPRESSIONLIST1'],['Email Address'],[Emai]);
    – syed Basha
    Apr 5, 2023 at 19:29
0

It worked with Lookup.

<script runat="server">
Platform.Load("core", "1");
var deleteDE = DataExtension.Init("Remove_Subscriber");
var data = deleteDE.Rows.Lookup(["toBeDeleted"], [true], 2, "Email");

for (var i = 0; i < data.length; i++) {
    var Emai = data[i].Email;
    var rowDelete = Platform.Function.DeleteData('Auto_Suppression_List',['Email 
Address'],[Emai]);
    var rows = Platform.Function.UpsertData("Remove_Subscriber",["Email"],[Emai],["Update"],[rowDelete]);
};
</script>

You must log in to answer this question.

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