1

The following code updates the Publication List status in the local Business Unit of the Landing Page, but I've got over 30 Business Units and I'm looking for a way to update all the publication lists at once from the top level Business Unit.

var subscriberObj = {
    "SubscriberKey": "test@test.com",
    "EmailAddress": "test@test.com"
}

var lists = List.Retrieve({
    Property: "ID",
    SimpleOperator: "equals",
    Value: 74800 //ListID in Child BU
})

var listKey = lists[0].CustomerKey
var list = List.Init(listKey) //Needs the ListKey for initialisation
var result = list.Subscribers.Update(subscriberObj, "Active")

I've tested the code above, and it doesn't work if it's at the top level Business Unit (Status: Error)

1

Depending on your BU configuration, you may find it easier to change All Subscribers status, which will flow to any Publication Lists. If that's not what you need, then SSJS and WSProxy will help you here. Specifically, using the Impersonation feature. This will probably work in a CloudPage, but might be better in a Script Activity in an Automation depending on the number of publication lists you are altering.

<script runat="server">
Platform.Load("core","1.1.5");        
var prox = new Script.Util.WSProxy();
var options = {SaveOptions: [{'PropertyName': '*', SaveAction: 'UpdateAdd'}]};
var email = 'test@email.com';
var subscriberkey = 'yourkey';

function unsub(obj) {
    prox.setClientId({ "ID": obj.mid }); //This will switch BU contexts
    var props = { 
        SubscriberKey: subscriberkey,
        EmailAddress: email,
        Lists: [{
            ID: obj.listID,
            Status: 'Unsubscribed'
        }]
    };
    var data = prox.updateItem("Subscriber", props, options);
    prox.resetClientIds(); //This will reset BU context
    return data.Results[0].StatusCode;
}

var myPubLists = [
    {mid:'123456', listID:'123'},
    {mid:'123456', listID:'456'},
    {mid:'654321', listID:'789'}
];

for (var i=0; i<myPubLists.length; i++) {
    var result = unsub(myPubLists[i]);
    Write("<br>Result:" + result);
}
</script>

Gathering the List IDs can be painful. If you don't already have a list, they can be retrieved with WSProxy also. You could combine with the above if you didn't have a static list of publists.

<script runat="server">
Platform.Load("core","1.1.5");
var prox = new Script.Util.WSProxy();
var queryAllAccounts = true;
var cols = ["Client.ID","CustomerKey","ListName","ID"];
var filter = {
    Property: "ListClassification",
    SimpleOperator: "equals",
    Value: "PublicationList"
};
var publists = prox.retrieve("List", cols, filter, queryAllAccounts);
Write(Stringify(publists));
</script>
  • Thank you for your example - it worked perfectly! Do you have any other WSProxy examples that I could refer to for other purposes? The official help documentation is notoriously scarce on the subject. – C Carswell Jun 14 at 19:51
  • I've pushed my examples to github. Feel free to fork/contribute any examples that you have. – Josh de Blank Jun 17 at 2:16
  • My man, you're a LEGEND - I'll definitely contribute when I have more examples! – C Carswell Jun 17 at 3:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.