0

The following code is supposed to change someone's status in a Publication List to "Active". It works very well when I run it via a CloudPage, but when I put it in an Automation Studio Script Activity it doesn't work. The subscriber's status remains "Unsubscribed" in the Publication List.

var person = {
    EmailAddress: '[email protected]',
    SubscriberKey: 'abc',
    Lists: {"Status": "Active", "ID": 123, "Action": "Upsert"}
  };
  var subObj = Subscriber.Init(emailaddr);
  var status = subObj.Upsert(person);

I have checked that the subscriber is still active in All Subscribers. Is changing the publication list status just something that can't be done in Automation Studio?

1 Answer 1

1

Update I just found the way to do that with SSJS core library

  • You would need to specify both CustomerKey and ID for the List
  • Initialize the subscriber by subscriber key
<script runat="server">
Platform.Load('core', '1.1.1');
var ListID = "Your List ID";
var ListCustKey = "Your List cust Key"

var person = {
    EmailAddress: '[email protected]',
    SubscriberKey: 'abc',
    Lists: {"CustomerKey": ListCustKey, "ID": ListID,"Status": "Active"}
  };
var subObj = Subscriber.Init(person.SubscriberKey);
var status = subObj.Upsert(person);
</script>

I don't think the reason is from Automation Studio but from my point of view, I would recommend using WSProxy library instead. Try something like this:

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

var ListID = "Your List ID";
var person = {
    EmailAddress: '[email protected]',
    SubscriberKey: 'abc'
  };

var prox = new Script.Util.WSProxy();

var sub = {
    SubscriberKey: person.SubscriberKey,
    EmailAddress: person.EmailAddress,
    Lists: [{
        ID: ListID,
        Status: 'Active'
    }]
};
var options = { 
    SaveOptions: [{
        PropertyName: "*",
        SaveAction: "UpdateAdd"
    }]
};

var resp = prox.createItem("Subscriber", sub, options);
</script>

Reference: Update via WSProxy

2
  • That worked! For reference, I used this code to retrieve the List Customer Key, with the value being the List ID number: List.Retrieve({Property:"ID",SimpleOperator:"equals",Value:1234})
    – K K
    Commented Feb 1, 2023 at 15:59
  • @KK I'm glad it was helpful. Thank you for accepting and upvoting the answer
    – Duc Le
    Commented Feb 2, 2023 at 2:58

You must log in to answer this question.

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