1
          var listName = ListArr[i].List.Name;
          var prefName = Variable.SetValue("@PrefName",listName);

          var list = List.Init(listName);
          var subbed = "";

          var checkSub = list.Subscribers.Retrieve({Property:"Subscriber Key",SimpleOperator:"equals",Value:subKey)};

This giving me a 500 error. I am trying to test a subscriber against all lists to see if they are subscribed. ListArr returns a info on spoof subscriber that is subbed to all lists in the BU so I can test checkSub against each list name and generate a checkbox accordingly. checkSub is causing the error, and I'm not sure what I am doing wrong with it. Is there a different way to see if a user is subscribed to a list, preferably through SSJS?

EDIT: Upon further investigation, none of the List Subscriber functions are working at all. I have hardcoded this:

  var subkey = "*My Email*";
  var MyList= List.Init(*List ID*);
  var Subs = MyList.Subscribers.Retrieve({Property:"SubscriberKey", SimpleOperator:"equals", Value:subkey});

And I have made sure I am the only person on that list. I still get zero results. In addition, I cannot add new subscribers to that any lists via ssjs and I cannot unsubscribe from lists via ssjs either.

  • Are you loading the platform core library like Platform.Load("Core","1.1.1"); at the start of that code? – Travis Naughton Jun 27 '18 at 23:42
  • Yeah, the rest of the ssjs works, but that one statement breaks it. – Matt Goldstein Jun 28 '18 at 3:03
  • Deleting the space in Subscriber Key allows the code to run, but now it is returning an empty array. It should return the EmailTypePreference for the subscriber it matches. – Matt Goldstein Jun 28 '18 at 15:58
  • @Matt Goldstein what is your requirement can you please explain clearly – pkharries Jul 5 '18 at 5:33
0

If you initiate the subscriber first before retrieving the lists, it will only retrieve the lists the subscriber is a part of.

Full example code below:

%%[
    SET @subscriberKey = _subscriberkey /*Retrieve the Subscriber Key into a variable*/
]%%

<script runat="server">
    Platform.Load("core", "1.1.1")
    var subKey = Variable.GetValue("@subscriberKey") //Assign to SSJS variable
    var subObj = Subscriber.Init(subkey) //Initiate Subscriber Object

    var listJSON = subObj.Lists.Retrieve() //Retrieve lists that the subscribers is a part of
    for (var i = 0; i < listJSON.length; i++){ //Loop through all the lists and print them out in HTML

        var listName = listJSON[i]["List"]["Name"]
        var listStatus = listJSON[i]["Status"]
 </script>

 <body>

     List Name:<ctrl:var name=listName /> <br />
     List Status:<ctrl:var name=listStatus /> <br />

 </body>

<script runat="server">
    Platform.Load("core", "1.1.1")    
    } //End of loop

    Write("Debug - Subscriber JSON:" + Stringify(listJSON)) //Used for debugging to find the object names

 </script>

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.