Search
  • Naveen VM

Add/Update All Subscribers from Data Extension via SSJS

Updated: May 21

Have you ever come across a scenario, where if a contact / lead changes its email address in Salesforce and in Marketing cloud the same contact / lead email address gets changed in synchronised data extension and normal data extension if you are using update / overwrite action while doing a SQL query. But it wouldn't have changed in All - subscriber list. This will result in sending an email to the old contact email address.


Or let's say you have added a new profile attribute called 'First name' and you would need to populate that value to all subscriber list from a master data extension.


For both the use cases you can add the below SSJS code in cloud page and update as an one time activity or you can add the SSJS in script activity in automation. So that it updates regularly.


With help of below code snippet of SSJS, you can add/update subscribers from Data extension.



Pre-Requisites:

  • Create a data extension. In the above example the data extension name is 'Test_AddSubscribers'

  • 'IsSubscriber' is one of the column in data extension where it shows the subscriber has been added for new subscriber and updated for existing subscribers.

  • For demo purpose, I have kept subscriber key as email address, Change the Line No - 27 for changing the subscriber key to be added in all subscriber list.

Below is the properties for the data extension:

Note:


This will only retrieve and update / insert All subscribers up-to 2000 records at once. If you want to retrieve more than 2000 records, then you would need to tweak the code with pagination. In this way by running the same script you can retrieve the records from data extension and update/insert the all subscriber list.


But, consider SSJS will take so much time to update if you have so many records. The easiest way would be using Automation studio with Data Extract Activity (extract the data extension records in a csv format) > File Transfer (move the extracted record from safe house to marketing cloud SFTP) > Import (Import the file from SFTP to All subscribers list).


Out come:


  • If you just want to update but not to insert then remove the else part from the SSJS snippet.

  • If the email address is not present in all subscriber list it will add it in All - subscriber list and will update the data extension row as 'ok added'.

  • If the email address have matched then it will update the All subscriber list and will update the data extension row as 'ok updated'.


Please feel free leave your comments in case of any queries.

Happy Learning!


#SFMC #SSJS #Allsubscriberlist


0 views