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": "[email protected]",
    "EmailAddress": "[email protected]"
}

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 Answer 1

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 = '[email protected]';
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>
3
  • 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. Commented Jun 14, 2019 at 19:51
  • I've pushed my examples to github. Feel free to fork/contribute any examples that you have. Commented Jun 17, 2019 at 2:16
  • My man, you're a LEGEND - I'll definitely contribute when I have more examples! Commented Jun 17, 2019 at 3:29

You must log in to answer this question.

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