Advertisements

SF Marketing Cloud : Getting All the List associated to Subscriber Email Address

In Salesforce Marketing Cloud, most of the time we need to retrieve the Publication Lists associated to the Subscriber.

Please find below SSJS code snippet for same.

UI FORM SECTION

<!DOCTYPE html>
 <html>
 <title>Getting All the List associated to Subscriber Email Address</title>
 <body>
 <h2>Getting All the List associated to Subscriber EmailAddress</h2>
 <form action="URL OF PUBLISHED CLOUD PAGE" method="post">
 Enter Your Email Address Here:
 <input type="text" name="emailId" value="">
 <br>
 <input type="submit" value="Submit">
 </form>
 </body>
 </html>

PROCESSING PAGE SECTION :

<html>
 <title>Getting All the List associated to Subscriber Email Address</title>
 <body>
 <h2>Getting All the List associated to Subscriber EmailAddress</h2>
 <script runat=server>
 Platform.Load("Core","1");
 
 var emailId = Platform.Request.GetFormField('emailId');//This Value will come from UI Form
 var data = DataExtension.Init("SSJS_Preferences");
 var SubKey;
 
 //emailId = "test@test.com";//For Testing I have given manual email Id here.
 
 //Start : Getting Subscriber Key
 var subObj = Subscriber.Retrieve({Property:"EmailAddress",SimpleOperator:"equals",Value:emailId});
 for(i = 0 ; i<subObj.length; i++)
 {
 SubKey = subObj[i].SubscriberKey;
 }
 //End : Getting Subscriber Key
 
 var subObj = Subscriber.Init(SubKey);
 var listArray = subObj.Lists.Retrieve();
 Write(Stringify(listArray));
 </script>
 </body>
 </html>
Advertisements


Categories: Salesforce Marketing Cloud

Tags: , , , , , , , , , , , , , , , , , ,

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: