0

I just start learning WSProxy and I'm trying to build custom preference center in SFMC for multiple publication lists so I started with 2 test publication lists test1, test2. I use if else statement to update the subscriber status in each pub list based on the checkbox after the form has been submitted, but the issue is if only the first checkbox (Test1) checked the status become unsubscribed in both publication lists and If the second checkbox (Test2) checked the status active in both pub lists.

can someone please help me out here to point where the issue is?

<!DOCTYPE html>
<html>
  <head>
    <title>Custom Preference Center</title>
  </head>
  <body>
    <h1>Custom Preference Center</h1>
    <form method="post" action="%%=RequestParameter('PAGEURL')=%%">
      <input type="hidden" name="listid" value="xxxx" />
      
      <input type="checkbox" name="test1Checkbox" value="test1Checkbox"> Test1
  
 <br>

<input type="hidden" name="listid" value="xxxx" />
      
      <input type="checkbox" name="test2Checkbox" value="test2Checkbox"> Test2
  
 <br>
      
     
  <input id="submitted" type="hidden" name="submitted" value="submitted" />
      <input type="submit" value="Submit">
    </form>
   
  </body>
</html>
%%[ if RequestParameter("submitted") == "submitted" then ]%%
<script runat="server">    
    Platform.Load("core","1.1.1");
    try {
    var subkey = "[email protected]";
    var email = "[email protected]";
    var test1Checked = Platform.Request.GetFormField("test1Checkbox");
    var test2Checked = Platform.Request.GetFormField("test2Checkbox");
  

    var prox = new Script.Util.WSProxy();
      var options = { 
        SaveOptions: [{
          PropertyName: "*",
          SaveAction: "UpdateAdd"
        }]
    };

    // Set specific BU context if required
     prox.setClientId({ "ID": xxxxxx });
  
  
       // update the subscriber status in Test1 publication list
       if (test1Checked == "test1Checkbox") {
            var test1createItem = {
                SubscriberKey: subkey,
                EmailAddress: email,
                Status: "Active",
                Lists: [{
                 ID: "xxxx"
                 
     
                 
        }]
    };
            var test1UpdateResult = prox.createItem("Subscriber", test1createItem, options);
        } else {
            var test1createItem = {
                SubscriberKey: subkey,
                EmailAddress: email,
                Status: "Unsubscribed",
                Lists: [{
                 ID: "xxxx"
    
                 
                
        }]
    };
            var test1UpdateResult = prox.createItem("Subscriber", test1createItem, options);
        }
      
      //update the subscriber status in test2 publication list
      
      if (test2Checked == "test2Checkbox") {
            var test2createItem = {
                SubscriberKey: subkey,
                EmailAddress: email,
                Status: "Active",
                Lists: [{
                 ID: "xxxx"
                 
     
                 
        }]
    };
            var test2UpdateResult = prox.createItem("Subscriber", test2createItem, options);
        } else {
            var test2createItem = {
                SubscriberKey: subkey,
                EmailAddress: email,
                Status: "Unsubscribed",
                Lists: [{
                 ID: "xxxx"
    
                 
                
        }]
    };
            var test2UpdateResult = prox.createItem("Subscriber", test2createItem, options);
        }

   
  
    Write("Response: " + Stringify(resp));
    } catch (ex) {
  Write("<br>Error: " + Stringify(ex));
}
</script>
 %%[ ELSE ]%% %%[ ENDIF ]%%

0

You must log in to answer this question.