2

I have unsubscribed users using logunusbevent call in a custom unsubscribe landing pages. However, I couldn't resubscribe them again if they check the resubscribe checkbox, below are the codes that I have tried and I am trying to activate a subscriber in all subscriber list but the below codes are not working

<script type="text/javascript" runat="server">
         Platform.Load("Core","1");
         var subscriber = {"EmailTypePreference": "HTML","Attributes":{"First Name": "Test11", "Last Name": "User11","Status"  :"Active"}

};

var subObj = Subscriber.Init("subkey");
var status = subObj.Update(subscriber);
Write("Help"+status);

var myList = List.Init("All Subscribers - 9899");
var status1 = myList.Subscribers.Update("subkkey","Active");
Write("Help"+status1);

</script>
1

You can try this. It will update profile attributes & status both for all subscriber list.

<script  runat="server">
Platform.Load("core","1");
var subkey = "abc123";
var subObj = Subscriber.Init(subkey); 
var subs = subObj.Lists.Retrieve(); 
//Write(Stringify(subs) + "<br>");   // for test purpose

for (var i = 0; i < subs.length; i++) 
{
  // Write(subs[i].List.ID + "<br>"); // for test purpose   
  if(subs[i].Status == "Unsubscribed") // search for Unsubscribed in  all subscriber list one by one
  {                
        var testSubscriber = {              
            "SubscriberKey": subkey,
            "Attributes":{"First Name": "Test11", "Last Name": "Test"},
            "Lists": {"Status": "Active","ID": subs[i].List.ID, "Action": "Update"}
        };      
        var subObj1 = Subscriber.Init(subkey);
        var status = subObj1.Update(testSubscriber); 
        Write("status=" + status + "<br>");
  }  
} 
</script>

In above mentioned code, I am assuming that the user's subscriber key is available to process (same as your ref. code).

Note : List ID should be passed to re-subscribe user from all subscriber list

Steps:

Step-1. Create a object of subscriber

var subObj = Subscriber.Init(subkey); 

Step-2. Retrieve all subscriber list

var subs = subObj.Lists.Retrieve(); 

Step-3. Iterate for all available records of Subscriber list

for (var i = 0; i < subs.length; i++) // Write(subs[i].List.ID + "<br>"); // for test purpose

Step-4. Create user object for each subscriber list to update

var testSubscriber = {              
        "SubscriberKey": subkey, //1
        "Attributes":{"First Name": "Test11", "Last Name": "Test"}, //2
        "Lists": {"Status": "Active","ID": subs[i].List.ID, "Action": "Update"} //3
   }; 

Note:

1.(required) SubscriberKey is required field for update Subscriber

2.(Optional) If you want to update Attributes then pass all attributes as key value pair

3.(required in case of list) Pass Status, Id(ListId) & action that will perform on subscriber

//

Step-5. Create a new 'Subscribers' object to update

var subObj1 = Subscriber.Init(subkey);   
  1. Update user reord
var status = subObj1.Update(testSubscriber);
|improve this answer|||||
0

Thanks Kumar - I have tried your solution and I was unable to make it work. On Step 4, I've actually modified the object and it's working now - It might help other developers

var testSubscriber = {              
   "SubscriberKey": subkey, //1
   // NOT USED - "Attributes":{"First Name": "Test11", "Last Name": "Test"},
   "Lists": {"ID": subs[i].List.ID, "Action": "Update"}, //3
   "Status": "Active"
}; 
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.