2

I'm pretty new at SSJS, but I'm trying to run a script in automation studio that removes a subscriber from a list via the unsubscribe function (see: https://developer.salesforce.com/docs/atlas.en-us.mc-programmatic-content.meta/mc-programmatic-content/ssjs_listSubscribersUnsubscribe.htm)

The javascript is valid according to Automation Studio and it also runs without error. However, the subscriber is not removed from the list.

My script is as follows and the email address I am referring to exists within the list:

Platform.Load("core","1");   
var myList = List.Init("DeleteDelta");      
var status myList.Subscribers.Unsubscribe("[email protected]");

Hopefully someone can tell me what I am doing wrong!

8
  • you need to remove or unsubscribe the subscriber from particular list?
    – Ravi.A
    Jul 4, 2018 at 10:56
  • The goal is to remove it from the list (DeleteDelta), which will hopefully result that it is also removed from the all subscribers. According to the link, the unsubscribe function will result in the removal of the subsriber from the list. Jul 4, 2018 at 11:01
  • particular subscriber or all subscribers remove from list ?
    – Ravi.A
    Jul 4, 2018 at 11:02
  • I was now testing to remove 1 subscriber, but in the end I want to remove all the subscribers from the list so that they will also be removed/deleted from the all subscribers. Jul 4, 2018 at 11:05
  • So, all subscribers from the list Jul 4, 2018 at 11:06

2 Answers 2

2

@Rutger Vogelsang this code for deleting all subscriber from particular list

  <script runat="server">
 Platform.Load("Core","1");
var  myList = List.Init("external key here");
var listFields = myList.Subscribers.Retrieve();
 var listFieldsLength = listFields.length;
 if (listFieldsLength > 0) {
    for (var i = 0; i < listFieldsLength; i++) {
 var subObj = Subscriber.Init(listFields[i].SubscriberKey);
   var status = subObj.Remove();
    }
 }

2
  • Perfect! This removes subscribers from the list, keeps the list in tact but also removes the subscribers from the all subscriber! Jul 5, 2018 at 9:19
  • @Rutger Vogelsang give me score for my answer
    – Ravi.A
    Jul 5, 2018 at 9:22
0

@Rutger Vogelsang use like this for the above code

      <script runat="server" language="javascript">
       Platform.Load("Core","1");


         var myList = List.Init("use list external key here");

        var status = myList.Subscribers.Unsubscribe("[email protected]");

           Write(Stringify(status ));

       </script>
4
  • thank you very much. I ran the script and it changed the status of the subscriber to unsubscribed. Is there also a possibility to actually remove the subscriber or, even better, all the subscribers from the list? Jul 4, 2018 at 14:44
  • @Rutger Vogelsang make me best answer
    – Ravi.A
    Jul 4, 2018 at 14:48
  • @Rutger Vogelsang this code is working for your requirement please make me best answer
    – Ravi.A
    Jul 4, 2018 at 14:53
  • @Rutger Vogelsang this is for deleting all subscribers and list also use like this under list.init var subs = myList.Subscribers.Retrieve(); var status = myList.Remove();
    – Ravi.A
    Jul 5, 2018 at 5:24

You must log in to answer this question.

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