Last active
May 18, 2021 14:12
-
-
Save VijayaSankarN/03e127edc67fa0042146328a9f1f36fe to your computer and use it in GitHub Desktop.
Add the Data Extension records to Publication List using SSJS. Details: https://vijayasankarn.wordpress.com/2021/05/18/marketing-cloud-add-data-extension-records-to-publication-list-using-wsproxy/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script runat="server"> | |
Platform.Load("core", "1"); | |
var prox = new Script.Util.WSProxy(); | |
try { | |
var DE = "DataExtensionObject[MyDataExtension]", // Replace 'MyDataExtension' with your Data Extension Name | |
options = {SaveOptions: [{'PropertyName': '*', SaveAction: 'UpdateAdd'}]}, | |
cols = ["EmailAddress", "SubscriberKey"], // Replace the field names matching your Data Extension | |
moreData = true, | |
reqID = null, | |
numItems = 0; | |
while(moreData) { | |
moreData = false; | |
var data = reqID == null ? | |
prox.retrieve(DE, cols) : | |
prox.getNextBatch(DE, reqID); | |
if(data != null) { | |
moreData = data.HasMoreRows; | |
reqID = data.RequestID; | |
for (var i = 0; i < data.Results.length; i++) { | |
var result_list = data.Results[i].Properties; | |
var obj = {}; | |
for (k in result_list) { | |
var key = result_list[k].Name; | |
var val = result_list[k].Value | |
if (key.indexOf("_") != 0) obj[key] = val; | |
} | |
var publicationList = { | |
EmailAddress: obj[cols[0]], | |
SubscriberKey: obj[cols[1]], | |
Lists: [{ | |
ID: 1234, | |
Status: 'Active' | |
}] | |
}; | |
prox.updateItem('Subscriber', publicationList, options); | |
} | |
} | |
} | |
} catch(e) { | |
Write(Stringify(e)); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment