[SalesForce] SFMC – SSJS Bulk update to All Subscribers list

I would like to automate the process of updating statuses, emails and from names in All Subscribers list, but I would like to avoid using export/import or any AMPscript sitting outside of the Automation Studio. Instead I would like to use SSJS.

My data source is in a data extension, and from there I would like to be able to transfer the data on a reccuring basis to All Subscribers list.

I am well familiar with Automation Studio, but since I am new to SSJS, I would like to find out how to set a loop of some kind (if at all needed?) in below script and how to "set" my data extension as the source:

var subscriber = {
    "EmailTypePreference": "HTML",
    "Attributes":{"First Name": "Test", "Last Name": "User"}
};
var subObj = Subscriber.Init("SubKey");
var status = subObj.Update(subscriber);

https://developer.salesforce.com/docs/atlas.en-us.mc-programmatic-content.meta/mc-programmatic-content/ssjs_subscriberUpdate.htm

Any working examples of this code would be highly appreciated.

Thanks!

Best Answer

First of all: Welcome to Salesforce StackExchange! I'm afraid there is no standard code to post that works for everyone and details of your instance and data structure are needed. Stack exchange is meant to ask specific questions for example on problems in code you've written.

For the basic structures and syntax SSJS is just regular JavaScript. So if you like to learn how to do this, I'd suggest reading some JavaScript Tutorials as there are countless excellent ones that you can easily find on the internet.

Here you can find an article regarding Loops: MDN - Looping code

To have your data extension as "source" you need to query it using SSJS. Information can be found in the Salesforce documentation: Data Extension Retrieve.

An easier and more performant approach would be extracting the changed records and then importing them to Marketing Cloud. This can also be done completely inside Automation Studio. I don't know your exact use case, but it will most certainly include the following steps:

  1. SQL Query activity
  2. Data Extract Activity
  3. File Transfer Activity
  4. Import File Activity

A documented example, that compares a (synchronized) data extension with the all subscribers list and updates it, be found here: How to sync email address changes from Sales/Service Cloud to All Subscribers list in Salesforce Marketing Cloud?

Related Topic