2

We have developed a cloud page to update publication list to update status from Active to Unsubscribe or Unsubscribe to Active. If someone select the check box and click submit. This works fine in Child BU (used as sandbox environment). I copied exact same code and created new cloud page and new publication lists in parent BU (Used as production) and updated list ID accordingly but, publication list does not get updated. Not sure what is the issue.

Below is Landing page code

%%[
SET @paramJOBID = QueryParameter("jid")
SET @paramSID = QueryParameter("sid")
SET @emailAddress = QueryParameter("email")
SET @chkWeek1 = "527" /*360 for business*/
SET @chkWeek2 = "529" /*Connect with Capital*/
SET @chkWeek3 = "528" /*360 for Members*/
SET @chkWeek4 = "530" /*New product Offers*/
SET @allSub = "182" /*All Subscribers*/

SET @rrObj = CreateObject("RetrieveRequest") 

SetObjectProperty(@rrObj, "ObjectType", "Subscriber")
AddObjectArrayItem(@rrObj,"Properties","SubscriberKey")
AddObjectArrayItem(@rrObj,"Properties","EmailAddress")
AddObjectArrayItem(@rrObj,"Properties","Status")

SET @cObj = CreateObject("SimpleFilterPart")
SetObjectProperty(@cObj, "Property", "SubscriberKey")
SetObjectProperty(@cObj, "SimpleOperator", "equals")
AddObjectArrayItem(@cObj, "Value",@paramSID)

SetObjectProperty(@rrObj, "Filter", @cObj)

SET @ResultSet = InvokeRetrieve(@rrObj)

IF(Rowcount(@ResultSet)>0) THEN       
    SET @row = row(@ResultSet,1)        
    SET @Email_address = Field(@row,"EmailAddress")
    SET @status_ = Field(@row,"Status")
ENDIF

]%%
<script runat="server">
   Platform.Load("core","1");
     var sid_ = Variable.GetValue('@paramSID');
     for(var li = 1; li<=5; li++)
     {
     var chkTotal = "@chkWeek"+li;
     var chkGetVal = Variable.GetValue(chkTotal);
     //retrieve all lists
     var lists = List.Retrieve();
    for(var i=0; i<lists.length; i++)
    {
     /*Write(lists[i].ListName);*/
     if(lists[i].ID == chkGetVal)
     {
      var liid=lists[i].CustomerKey;
      var myList = List.Init(liid);
      var subs = myList.Subscribers.Retrieve({Property:"SubscriberKey", SimpleOperator:"equals", Value:sid_});
      var count =subs.length;
      if(count > 0)
      {
       for(var j=0; j<count; j++)
       {
         (subs[j].Status);
         if(subs[j].Status == "Unsubscribed")
         {
           var chkSetVal = "@week"+li;
        Variable.SetValue(chkSetVal,"True");
         }
         else
         {
        var chkSetVal = "@week"+li;
        Variable.SetValue(chkSetVal,"False");
         }
       }
      }
     }
    }
    }
</script> 

Here is the Processing Page Code

%%[
SET @chkVal_0 = RequestParameter("week1")
SET @chkVal_1 = RequestParameter("week2")
SET @chkVal_2 = RequestParameter("week3")
SET @chkVal_3 = RequestParameter("week4")
SET @chkVal_4 = RequestParameter("ckbCheckAll")
SET @pubListID_0 = "527"
SET @pubListID_1 = "529"
SET @pubListID_2 = "528"
SET @pubListID_3 = "530"
SET @pubListID_4 = "182"
SET @paramJOBID_ = RequestParameter("jid")
SET @paramSID_ = RequestParameter("sid")
SET @email_ = RequestParameter("email")
]%%
<script runat="server">
Platform.Load("Core","1");
try{
 var chkAllVal_ = Variable.GetValue("@chkVal_4");
 if (chkAllVal_ !="")
 {
</script>
%%[
SET @Unsub_All = "Unsubscribed"
/*Update the unsubscribe from all list*/  
SET @ll_sub = CreateObject("Subscriber")

SetObjectProperty(@ll_sub,"EmailAddress", @email_)
SetObjectProperty(@ll_sub,"SubscriberKey", @paramSID_)

SET @client = CreateObject("ClientID")
SetObjectProperty(@client, "ID", "110006544")
SetObjectProperty(@client, "IDSpecified", "true")
SetObjectProperty(@ll_sub, "Client", @client)

SetObjectProperty(@ll_sub,"Status", @Unsub_All)
Set @options = CreateObject("UpdateOptions")
Set @save = CreateObject("SaveOption")
SetObjectProperty(@save,"SaveAction","UpdateAdd")
SetObjectProperty(@save,"PropertyName","Status")
AddObjectArrayItem(@options,"SaveOptions", @save)

/* Here is where we actually update the Subscriber object */
Set @update_sub = InvokeUpdate(@ll_sub, @update_sub_status, @update_sub_errorcode, @options)

]%%

<script runat="server">
 }
 else
 {

 </script>
%%[
SET @Active_All = "Active"
/*Update the unsubscribe from all list*/  
SET @ll_sub = CreateObject("Subscriber")

SetObjectProperty(@ll_sub,"EmailAddress", @email_)
SetObjectProperty(@ll_sub,"SubscriberKey", @paramSID_)

SET @client = CreateObject("ClientID")
SetObjectProperty(@client, "ID", "110006544")
SetObjectProperty(@client, "IDSpecified", "true")
SetObjectProperty(@ll_sub, "Client", @client)

SetObjectProperty(@ll_sub,"Status", @Active_All)
Set @options = CreateObject("UpdateOptions")
Set @save = CreateObject("SaveOption")
SetObjectProperty(@save,"SaveAction","UpdateAdd")
SetObjectProperty(@save,"PropertyName","Status")
AddObjectArrayItem(@options,"SaveOptions", @save)

/* Here is where we actually update the Subscriber object */
Set @update_sub = InvokeUpdate(@ll_sub, @update_sub_status, @update_sub_errorcode, @options)
]%%
<script runat="server">
 }
 }
catch(e){
 Write(Stringify(e));
}
</script>

<script runat="server">
Platform.Load("core","1");
  var prox = new Script.Util.WSProxy();
  var email = Variable.GetValue("@email_");
  var sidVal = Variable.GetValue("@paramSID_");
  var jidVal = Variable.GetValue("@paramJOBID_");

 var allPublicationLists = getAllPublicationLists();
 for (var i in allPublicationLists) 
    {
      var chkValDyn = "@chkVal_"+i;
      var chkGetValDyn = Variable.GetValue(chkValDyn);
      var pubListID = "@pubListID_"+i;
      var pubListIDVal = Variable.GetValue(pubListID);

        if(allPublicationLists[i]["ID"] == pubListIDVal)
        {
          if (chkGetValDyn != "")
          {
            ("<br/>"+"Unsub")
            var sub = { 
                 SubscriberKey: sidVal, 
                 EmailAddress: email,
                        Lists: [{
                            ID: pubListIDVal,
                            Status: "Unsubscribed"
                        }]
   };
            var options = { 
                           SaveOptions: [{
                            PropertyName: "*",
                            SaveAction: "UpdateAdd"
      }]
   };
            var resp = prox.createItem("Subscriber", sub, options);
   ("Response: " + Stringify(resp));
          }
          else
          {
            ("Active")
            var sub = { 
                 SubscriberKey: sidVal, 
                 EmailAddress: email,
                        Lists: [{
                            ID: pubListIDVal,
                            Status: "Active"
                        }]
   };
            var options = { 
                           SaveOptions: [{
                            PropertyName: "*",
                            SaveAction: "UpdateAdd"
      }]
   };
            var resp = prox.createItem("Subscriber", sub, options);
   ("Response: " + Stringify(resp));
          }
  }
    }    

    function getAllPublicationLists() {

        var rr = Platform.Function.CreateObject("RetrieveRequest");
        Platform.Function.SetObjectProperty(rr, "ObjectType", "Publication");
        Platform.Function.SetObjectProperty(rr, "QueryAllAccounts", "True");

        Platform.Function.AddObjectArrayItem(rr, "Properties", "ID");
        Platform.Function.AddObjectArrayItem(rr, "Properties", "Name");
        Platform.Function.AddObjectArrayItem(rr, "Properties", "Category");
        Platform.Function.AddObjectArrayItem(rr, "Properties", "Client.ID");

        var reqParams = [0,0];
        var publications = Platform.Function.InvokeRetrieve(rr, reqParams);

        return publications;
    } 
</script>
4
  • can you share the code? Without the code its hard to help debug what could be wrong Commented Feb 23, 2020 at 16:06
  • @Gortonington: Updated the question with code
    – Harish
    Commented Feb 24, 2020 at 1:24
  • To verify you changed the clientid (currently 110006544) to the parent account MID, right? If not, then it is making these changes in that BU. Now the WSProxy is BU based, so that should work to a degree, depending on Subscriber All Subs status. Commented Feb 24, 2020 at 14:57
  • Yes. I did change the clientid. Still not working
    – Harish
    Commented Feb 28, 2020 at 16:26

0

You must log in to answer this question.

Browse other questions tagged .