4. Subscriber Based Scenario - Richard98PL/SFMC-Profile-Subscription-Center GitHub Wiki
-
HTML Preference
var results = Subscriber.Retrieve({Property:"EmailAddress",SimpleOperator:"equals",Value:email}); var emailTypePreference = results[0]["EmailTypePreference"];
-
Attributes Retrieve
var subscriber_object = Subscriber.Init(email); var attributes = subscriber_object.Attributes.Retrieve(); for(var i = 0; i<attributes.length; i++){ if(attributes[i].Name === "First Name"){ var firstName = attributes[i].Value; } if(attributes[i].Name === "Preference 1"){ var firstName = attributes[i].Value; } }
-
Lists Retrieve
var subscriber_object = Subscriber.Init(email); var lists = subscriber_object.Lists.Retrieve(); for(var i = 0; i < lists.length ; i++){ if(lists[i]["List"]["Name"] === "All Subscribers"){ if(lists[i]["Status"] == "Active"){ //"Active"/"Unsubscribed" //... logic here } } }
-
Attributes Update
var data = { "EmailTypePreference": emailTypePreference, "Attributes": { "First Name": firstName, "Last Name": lastName } } var subscriber_object = Subscriber.Init(email); var status = subscriber_object.Update(data);
-
All Subscribers Unsubscribe
var subscriber_object = Subscriber.Init(email); var status = subscriber_object.Remove();
-
Custom List Unsubscribe
var myList = List.Init("ListKey"); var status = myList.Subscribers.Unsubscribe(email);
-
Custom List Subscribe
var myList = List.Init("ListKey"); var status = myList.Subscribers.Upsert(email);