I have a temporary data extension (will be updated daily) with subscribers need to be unsubscribed. It looks like this:
SubscriberKey, EmailAddress and Status were queried from All Subscribers list (ent.__Subscribers
)
And a logging data extension to store logs.
In order to unsubscribe, I used a script activity:
<script runat="server" type="text/javascript">
Platform.Load("core", "1");
var unsubDE = DataExtension.Init('424ded4d-88cd-eb11-b824-48df37dc126b');
var data = unsubDE.Rows.Retrieve();
var logging = [];
if(data.length > 0) {
for (var i = 0; i < data.length; i++)
{
var SubId = data[i].SubscriberKey;
var subObj = Subscriber.Init(SubId);
var status = subObj.Unsubscribe();
if (status != "error") {
logging.push({SubscriberKey: SubId, EmailAddress: data[i].EmailAddress, Email_Status: data[i].Email_Status, Status: 'Unsubscribe Complete', Timestamp: Date.now()});
} else {
logging.push({SubscriberKey: SubId, EmailAddress: data[i].EmailAddress, Email_Status: data[i].Email_Status, Status: 'Error Processing Optout', Timestamp: Date.now()});
};
};
var loggingDE = DataExtension.Init('f222668a-c0cd-eb11-b824-48df37dc126b');
loggingDE.Rows.Add(logging);
};
</script>
I get the ID 424ded4d-88cd-eb11-b824-48df37dc126b
of the temporary data extension and the remaining one by this Way
Then run once for the script activity. However, it hasn't been added into the logging data extension after that and the subscriber hasn't been unsubscribed (checked in all subscribers list).
I'm not sure how to debug and fix it. Really appreciate if anyone can take a look at it.
P/s: the idea came from an Answer on salesforce stackexchanger.