0

I'm learning to build a custom preference centre and trying to display all the lists for a subscriber. I retrieved all the lists like below:

<script runat='server' type="text/javascript">
   Platform.Load('core', '1');
   var prox = new Script.Util.WSProxy();

   //Retrieve a subscriber and their lists
   var sk = Attribute.GetValue('_subscriberkey')
   if(sk) {
      var subObj = Subscriber.Init(sk)
      var subData = Subscriber.Retrieve({
        Property: 'SubscriberKey',
        SimpleOperator: 'equals',
        Value: sk
      })
      //Retrieve the list property
      var subLists = subObj.Lists.Retrieve({
            Property: "Type",
            SimpleOperator: "equals",
            Value: "Public"
      })

   }
   try{
</script>
          
<script type="text/javascript" runat="server">
   Write(Stringify(subLists))
   }
   catch(e) {
   Write(Stringify(e));
   }
</script>

And I was able to output the all the lists with the Write()function (which is an array of json objects). But when I tried to console.log the subLists with Vuejs, I got undefined (note that I was able to console.log other variables like email and sk).

<div id="app">
     <button @click="debug">Console</button>
</div>

<script>
  new Vue({
    data(){
      subscriber: {
        lists: '<ctrl:var name="subLists"/>'
      }
    },
    methods: {
      debug(){
        console.log(this.subscriber.lists)
      }
    }
  })
</script>

I'm not sure why I got undefined when trying to console.log the list array. Any help would be appreciated. Thanks!

4
  • Probably don't need the single quotes on this line: lists: '<ctrl:var name="subLists"/>' Commented May 10, 2022 at 14:07
  • Hey. I removed the single quotes but still got undefined.
    – Simon
    Commented May 10, 2022 at 15:43
  • If you replace the value for lists with static text, does your debug button return it? Commented May 10, 2022 at 17:32
  • I figured it out that I should have Stringify the subLists first: subLists = Stringify(subLists). And now it worked. Thanks, Adam.
    – Simon
    Commented May 10, 2022 at 18:08

1 Answer 1

1

I figured it out that I had to stringify the subLists first: subLists = Stringify(subLists)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .