1

We have 3 subscription lists called: promotions, newsletter and pharmaceutical advice. As our client doesn't like the standard preference center, he asked us to custom-built it.

So far the functionality is working but it feels like a very dirty solution. Because we are using lists instead of data extensions, we have to retrieve and update the data through SSJS. To ensure the local checkboxes can use the SSJS functionality, we used different landing pages that are called. On these landing pages we then call the function to update the subscriber.

See code below:

<form name="_objForm" method="post" action="./subscription_center.aspx?orginfo" id="_objForm">

    <table cellpadding="0" cellspacing="0" border="0">

            <script runat="server" language="javascript">

                Platform.Load("core", "1");
                // Get the lists through the external keys
                var promotions = List.Init('Promotions - 382');
                var newsletter = List.Init('Monthly newsletter - 382');
                var advice = List.Init('Advice from the pharmacist - 382');

                // Get subscriberkey from the email context
                var subscriberKey = Attribute.GetValue("_subscriberkey");

                /*
                 var language = Variable.GetValue("@language"); 
                var subscriberKey = Variable.GetValue("@subscriberKey");  
                */
                Write('<div id="subscriberKey">' + subscriberKey + '</div>');
                // Get the subscriber status for the promotion list
                var promotionSubscriber = promotions.Subscribers.Retrieve({ Property: "SubscriberKey", SimpleOperator: "Equals", Value: subscriberKey });
                var promotionStatus = promotionSubscriber[0].Status;

                // Get the subscriber status for the newsletter list
                var newsletterSubscriber = newsletter.Subscribers.Retrieve({ Property: "SubscriberKey", SimpleOperator: "Equals", Value: subscriberKey });
                var newsletterStatus = newsletterSubscriber[0].Status;

                // Get the subscriber status for the advice list
                var adviceSubscriber = advice.Subscribers.Retrieve({ Property: "SubscriberKey", SimpleOperator: "Equals", Value: subscriberKey });
                var adviceStatus = adviceSubscriber[0].Status;

                //promotionStatus
                Write('<tr><td class="tdListCheck">')
                if (promotionStatus == "Active") {
                    Write('<input onclick="doPostpromotionStatus()" type="checkbox" id="promoBox" checked>')

                } else {
                    Write('<input onclick="doPostpromotionStatus()" type="checkbox" id="adviceBox">')
                }
                Write('</td><td class="tdListInfo" id="test">' +
                    '<b>Promoties</b>' +
                    '</td></tr>');

                //newsletterStatus
                Write('<tr><td class="tdListCheck">')
                if (newsletterStatus == "Active") {
                    Write('<input onclick="doPostnewsletterStatus()" type="checkbox" id="newsBox" checked>')
                } else {
                    Write('<input onclick="doPostnewsletterStatus()" type="checkbox" id="adviceBox">')
                }
                Write('</td><td class="tdListInfo" id="test">' +
                    '<b>Maandelijkse nieuwsbrief</b>' +
                    '</td></tr>');

                //adviceStatus
                Write('<tr><td class="tdListCheck">')
                if (adviceStatus == "Active") {
                    Write('<input onclick="doPostadviceStatus()" type="checkbox" id="adviceBox" checked>')
                } else {
                    Write('<input onclick="doPostadviceStatus()" type="checkbox" id="adviceBox">')
                }
                Write('</td><td class="tdListInfo" id="test">' +
                    '<b>Advies van de apotheker</b>' +
                    '</td></tr>');

                //var status = promotions.Subscribers.Update(subscriberKey, "Unsubscribed");
            </script>

    </table>
</form>


<script type="text/javascript">
    function doPostpromotionStatus(){
        window.location.href = window.location.origin + "/promotionSubscriber" + window.location.search;
    }
    function doPostnewsletterStatus(){
        window.location.href = window.location.origin + "/newsletterStatus" + window.location.search;
    }
    function doPostadviceStatus(){
        window.location.href = window.location.origin + "/adviceStatus" + window.location.search;
    }

</script>

On the different landing pages we then have this code (e.g., promotion list):

<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>
    <div>

        <script runat="server" language="javascript">

            Platform.Load("core", "1");
            // Get the lists through the external keys
            var promotions = List.Init('Promotions - 382');

            // Get subscriberkey from the email context
            var subscriberKey = Attribute.GetValue("_subscriberkey");

            /*
             var language = Variable.GetValue("@language"); 
            var subscriberKey = Variable.GetValue("@subscriberKey");  
            */
            Write('<div id="subscriberKey">' + subscriberKey + '</div>')
            // Get the subscriber status for the promotion list
            var promotionSubscriber = promotions.Subscribers.Retrieve({ Property: "SubscriberKey", SimpleOperator: "Equals", Value: subscriberKey });
            var promotionStatus = promotionSubscriber[0].Status;

            //promotionStatus
            if (promotionStatus == "Active") {
                var status = promotions.Subscribers.Update(subscriberKey, "Unsubscribed");

            } else {
                var status = promotions.Subscribers.Update(subscriberKey, "Active");
            }



        </script>
     <img src="https://media3.giphy.com/media/3oEjI6SIIHBdRxXI40/giphy.gif" width="256" height="256">
        <script type="text/javascript">

            window.location.href = window.location.origin + "/Subscriptions" + window.location.search;

        </script>
    </div>
</body>

</html>

Your Answer

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

Browse other questions tagged or ask your own question.