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 the 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 lists from a master data extension.
For both the use cases you can add the below SSJS code in the cloud page and update as a one time activity or you can add the SSJS in script activity in automation. So that it updates regularly.
With help of the below code snippet of SSJS, you can add/update subscribers from Data extension (view code snippet).
Pre-Requisites:
Create a data extension. In the above example the data extension name is 'Test_AddSubscribers'
'IsSubscriber' is one of the columns in the data extension where it shows the subscriber has been added for new subscriber and updated for existing subscribers.
For demo purposes, I have kept the subscriber key as an email address, Change the Line No - 27 for changing the subscriber key to be added in all subscriber lists.
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.
Also, if you are planning to change the status from Active to unsubscribe then you would need to call the 'Unsubscribe' method instead of 'update' method.
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 has matched then it will update the All subscriber list and will update the data extension row as 'ok updated'.
Please feel free to leave your feedback/comments in case of any queries.
Happy Learning!
Hi Naveen, I need to update subscribers in SFMC all subscribers (parent and child BU) and need to verify updated in synchronized DE per list i have could you help me with that please?
Hi Naveen
I want to change the subscriber status from Held to Active via automation studio.
Can you help me with this?
Hi, Thank you for the above! But when I am running the code the subscribers are not getting pushed out from Data extension to publication list. Can you please help?
Hi, congratulations! Really good job, I would like to know if it's possible to move data from a list to a data extension
I am trying to change the Status 'Active' to 'Unsubscribe' as you said to use Unsubscribe Method but nothing happened. It shows this error "A runtime error occurred while the SSJS Activity executed the SSJS script. Please review the SSJS activity to ensure that errors are handled properly." Please let me know what to do in this case.