I am building a cloudpage to replace the standard subscription center. I want handle the email list subscriptions in there through checkboxes.

I am already stuck at visualizing the subscription lists.

The code I have so far is the following:

var myList = List.Init('Promotions')

var subs = myList.Subscribers.Retrieve({Property:"Email Address", SimpleOperator:"equals", Value:"testSFMC@gmail.com"})

When trying to generate the cloudpage, I get an internal server error. This indicates that something is wrong with AMPscript but I don't know what.

Edit: New code

<script type="javascript" runat="server">
var promotions = List.Init('Promotions');

var subscriber = promotions.Subscribers.Retrieve({Property:"Email Address",SimpleOperator:"equals", Value:"matthias.claes@forward.eu"});

Variable.SetValue("subscriber", subscriber);
set @rowCount = rowcount(@subscriber)

var @status
var @subscriberKey
set @status = "empty1"
set @subscriberKey = "empty2"

if @rowCount > 0 then
  set @row = row(@subscriber,1) /* get row #1 */
  set @status = field(@row,"Status")
  set @subscriberKey = field(@row,"Subscriber Key")

%%=v(@status)=%% <br>
%%=v(@subscriberKey)=%% <br>

this is not AMPScript, you are writing Server Sided JavaScript. If you WERE using AMPScript, the closing tag should look like this though: ]%%

When working with lists, refer to the documentation for SSJS. In general, working with lists is a lot harder than working with data extensions in this regard. probably not an option, just wanted to note it.

With that said, the following should be wrapping your code - Start by loading the Core Library, otherwise the list.Subscribers method does not work: https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-programmatic-content.meta/mc-programmatic-content/ssjs_listFunctions.htm

<script type="javascript" runat="server">
/* your code here */

If you want to display the "@subs" AMPScript variable, you can set the AMPSCript variable from Javascript using Variable.SetValue():


in sum, this would be my starting point (untested).

<script type="javascript" runat="server">
var myList = List.Init('Promotions');
var subs = myList.Subscribers.Retrieve({Property:"EmailAddress",SimpleOperator:"equals", Value:"testSFMC@gmail.com"});

Hope this helps :)

  • Oh didn't know that when working with lists it has to be SSJS! Thanks a lot! I've updated my code to the following (see post), but it still returns "empty" for both attributes. How does SSJS deal with attributes that have spaces? – user3485470 Jul 22 at 12:11

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.